1

I am getting 'application defined or object defined object error' for the following code

10        Sheets("Main").Select
20        currYearDate = DateValue("April 1, " & Year(Now))
30        nextYearDate = DateValue("March 31, " & (Year(Now) + 1))
40        Range("H9").Activate
50        With ActiveCell.Validation
60            .Add Type:=xlValidateDate, AlertStyle:=2, Operator:=1, Formula1:=currYearDate, Formula2:=nextYearDate
70            .ErrorMessage = "You should enter date between " & Format(DateValue("April 1," & Year(Now)), "dd-mmm-yyyy") & " and " & Format(DateValue("March 31," & Year(Now) + 1), "dd-mmm-yyyy")
80            .ErrorTitle = "Warning Message"
90        End With

can anybody help me out?

0

1 Answer 1

2

Try below code :

 Sheets("Main").Select
    currYearDate = DateValue("April 1, " & Year(Now))
    nextYearDate = DateValue("March 31, " & (Year(Now) + 1))
    With Range("H9").Validation
        .Delete
        .Add Type:=xlValidateDate, AlertStyle:=2, Operator:=1, Formula1:=currYearDate, Formula2:=nextYearDate
        .ErrorMessage = "You should enter date between " & Format(DateValue("April 1," & Year(Now)), "dd-mmm-yyyy") & " and " & Format(DateValue("March 31," & Year(Now) + 1), "dd-mmm-yyyy")
        .ErrorTitle = "Warning Message"
    End With
Sign up to request clarification or add additional context in comments.

Comments

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.