98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Do loop
Do loop
Resolved · Low Priority · Version 2010
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
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Formula for last day of monthIn some cases it is necessary to find the last day of a month for a given date. If you use the following formula, you can achieve this, ie; if you have a column of dates, use this formula to find the end of month for each day by using the fill handle. The formula is as follows, and assumes in this example that the first date in question is in cell C5, in any other cell type; =DATE(YEAR(C5),MONTH(C5)+1,1)-1 |