1

I went throught various threads and got several tips on Validation. But still my code is throwing me an error. It could be a silly error but i couldn;t spot it.

        Set val1range = projInfo.Range(projInfo.Cells(2, 23), projInfo.Cells(m, 23))     

        With Cells(rowN, 3).Validation
                .Delete
                .Add Type:=xlValidateList, Formula1:="=" & val1range

                .IgnoreBlank = True
                .InCellDropdown = True
                .InputTitle = ""
                .ErrorTitle = ""
                .InputMessage = ""
                .ErrorMessage = ""
                .ShowInput = True
                .ShowError = True
        End With

I am getting a 1004 error on the line .Add Application-defined or object-defined error.

Could youplease let me know if i am giving the correct formula?

3
  • What part of the code is causing the error? Commented Nov 4, 2013 at 22:27
  • i am getting at .Add line Commented Nov 5, 2013 at 15:10
  • I think it could be due to the fact that you .Delete the row and then reference it straight after. Try calling the Delete Method outside the With Block Commented Nov 5, 2013 at 17:10

1 Answer 1

2

Not sure if this is the only error, since the code you posted doesn't define projInfo, m, or rowN, but your Add method is attempting concatenate a string, "=", and a range object, val1Range. The default property of Range objects is Value, so in effect you're concatenating "=" with the value or content of the cell instead of its address (which is presumably what you want).

To fix, change this line:

.Add Type:=xlValidateList, Formula1:="=" & val1range

to this:

.Add Type:=xlValidateList, Formula1:="=" & val1range.Address
Sign up to request clarification or add additional context in comments.

1 Comment

the projinfo, m rowN are all defined in previous lines and they all hold vaild values. Just i didn't show them here.. and i am sorry about that. I gave the fix you suggested. Still i am getting the same error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.