Select Case within IF-Else statement
Sub test()
With rngTopLeft.Offset(0, 1)
If rngTopLeft.Value = "" Then
'color blue/beige (37 for weekend, 40 for weekday)
Select Case Weekday(rngTopLeft.Value)
Case 1, 7 'Sunday or saturday
.Interior.ColorIndex = 37
Case Else
.Interior.ColorIndex = 40
End Select
Else
End If
End With
syntactically worked fine for me. Possibly you had some type of typo.
However, since the test is if the cell is empty, it seems pointless to have a
case statement looking for values in the cell.
--
Regards,
Tom Ogilvy
"rwnelson" wrote:
I'm trying to edit the following code but when I put the Select Case
after Then instead of after Else, it gives me an error. Why would it
work for one but not the other? I'm a VBA beginner.
If rngTopLeft.Value = "" Then
.Interior.ColorIndex = 15
Else
'color blue/beige (37 for weekend, 40 for weekday)
Select Case Weekday(rngTopLeft.Value)
Case 1, 7 'Sunday or saturday
.Interior.ColorIndex = 37
Case Else
.Interior.ColorIndex = 40
End Select
End If
|