Article ID: 113659
Article Last Modified on 10/10/2006
Sub TestDate()
'The following nested case statement determines if a date within
'a column of dates falls within a certain range. If the beginning date
'or the ending date is within or out of the range, it displays a message
'in the next column.
begin_date = DateValue(InputBox(prompt:="Enter the beginning date"))
end_date = DateValue(InputBox(prompt:="Enter the ending date"))
Do While ActiveCell <> ""
'Checks the date of the current cell.
Select Case ActiveCell
Case Is >= begin_date
'Nested Case to check for ending date of current cell.
Select Case ActiveCell
Case Is <= end_date
ActiveCell.Offset(0, 2) = "Meets criteria"
'Does this if the ending date is out of range.
Case Is >= end_date
ActiveCell.Offset(0, 2) = "Ending date out of range"
End Select
'Does this if the beginning date is out of range.
Case Else
ActiveCell.Offset(0, 1) = "Beginning date is out of range"
End Select
'Selects the next cell on the active worksheet.
ActiveCell.Offset(1, 0).Select
Loop
End Sub
Additional query words: 8.00 97 HOWTO nest case if XL
Keywords: kbprogramming KB113659