Setting validation via VBA in excel fails when using variable

后端 未结 6 2051
野趣味
野趣味 2021-01-06 07:56

I am trying to set the data validation for a range of cells using VBA. I get a run-time error 1004 (so helpful) \"Application defined or object defined error\" with this cod

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-06 08:41

    This is a pretty old post but for anyone getting here with the the same issue I did, here is how the problem was solved in my case:

    I just replaced the

    With Range(Cell1,Cell2).Validation
    

    part by

    Range(Cell1,Cell2).Select
    With Selection.Validation
    

    And tadaaa! it works :)

提交回复
热议问题