title: Data validation using VBA
body: <p>I am getting 'application defined or object defined object error' for the following code</p>
  
  <pre><code>10        Sheets("Main").Select
  20        currYearDate = DateValue("April 1, " &amp; Year(Now))
  30        nextYearDate = DateValue("March 31, " &amp; (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 " &amp; Format(DateValue("April 1," &amp; Year(Now)), "dd-mmm-yyyy") &amp; " and " &amp; Format(DateValue("March 31," &amp; Year(Now) + 1), "dd-mmm-yyyy")
  80            .ErrorTitle = "Warning Message"
  90        End With
  </code></pre>
  
  <p>can anybody help me out?</p>