Natasha has attended:
Excel Advanced course
Excel VBA Introduction course
Excel Advanced - Formulas & Functions course
Excel VBA Intermediate course
Excel Dashboards for Business Intelligence course
Excel Forecasting and Data Analysis course
Excel VBA Advanced course
Do loop
I have written the following macro that highlights the active cell if it has the value "Wednesday" and if another cell (same row and three columns across) has a time value > 12pm.
Would you be able to advise why this does not work?
Sub WedsPM()
Range("I2").Select
Do Until ActiveCell = ""
If ActiveCell.Value = "Wednesday" And ActiveCell.Offset(0, 3).Value > Time(12, 0, 0) Then
ActiveCell.Interior.ColorIndex = 27
End If
ActiveCell.Offset(1, 0).Select
Loop
End Sub
RE: Do loop
Hi Natasha,
Thank you for your post. The code below worked for me. I changed the time reference to a value of 0.5, which means 12 PM (halfway through 1 day). Make sure your time cells are formatted as time.
Sub WedsPM()
Range("I2").Select
Do Until ActiveCell = ""
If ActiveCell.Value = "Wednesday" And ActiveCell.Offset(0, 3).Value > 0.5 Then
ActiveCell.Interior.ColorIndex = 27
End If
ActiveCell.Offset(1, 0).Select
Loop
End Sub
Kind regards
Marius Barnard
STL