How about this:
Private Sub CommandButton3_Click()
On Error Resume Next
from = Application.InputBox(Prompt:="Please enter from date", Title:="From Date", Default:="Example: 01/01/2009")
tofrom = Application.InputBox(Prompt:="Please enter to date", Title:="To Date", Default:="Example: 31/01/2009")
If from = False Or from Like "Example:*" Or tofrom = False Or tofrom Like "Example:*" Then
MsgBox "Dates were not entered correctly, please try again."
Exit Sub
End If
myrow = WorksheetFunction.Match(Range("C9"), Sheets("HOLS").Range("A:A"), 0)
Cols = Sheets("HOLS").Cells(myrow, Columns.Count).End(xlToLeft).Column
For i = 1 To Cols
If Sheets("HOLS").Cells(myrow, i) = from Or Sheets("HOLS").Cells(myrow, i) = tofrom Then
MsgBox "Not available"
Exit Sub
ElseIf Sheets("HOLS").Cells(myrow, i) > from And Sheets("HOLS").Cells(myrow, i) < tofrom Then
MsgBox "Not available"
Exit Sub
End If
Next i
MsgBox "Available"
Range("D61").Value = from
Range("E61").Value = tofrom
End Sub
NOTE: you only need to put the "on error resume next" line in a macro once unless you later change it to something else, it's in effect all the time.
Bookmarks