PDA

View Full Version : [SOLVED] Why is this loop not working?



TLP
08-30-2013, 06:31 AM
Hi,

This is what I am trying to do:

Starting at cell C38, I want to test to see if the cell is blank and if it is blank, insert today's date that will be fixed (so no =today()) and then call a certain macro (Macro X) and then move to the next cell to the right and repeat the same process. If there is already a date in the cell just move onto the next cell anyway. At the end of the row I will put a stop marker in a cell such as the letter E and obviously the cells after will be blank and it will go into an indenfinate loop.

This is what I have written, but I am getting "compile error loop without do". I feel as though I am kind of going in the right direction, but my brain is failing me.

Can anyone help?

Cheers,

TLP.

raj85
08-30-2013, 07:13 AM
Please provide your code to assist you ;)

TLP
08-30-2013, 07:21 AM
Yes, that would help! Silly mistake - here is my code:

Sub SendAllInsxToAgents()
Dim lCol As Long
lCol = 3

Do Until Cells(38, lCol).Value = "E"

If Cells(38, lCol).Value = "" Then
Cells(38, lCol).Value = "=Today()"
Run Macro
lCol = lCol + 1
If Cells(38, lCol).Value <> "" Then
lCol = lCol + 1
Loop
End Sub

raj85
08-30-2013, 07:45 AM
You missed 'END IF' and 'ELSE' part of IF block

Sub SendAllInsxToAgents()
Dim lCol As Long
lCol = 3
Do Until Cells(38, lCol).Value = "E"
If Cells(38, lCol).Value = "" Then
Cells(38, lCol).Value = "=Today()"
Call test
lCol = lCol + 1
ElseIf Cells(38, lCol).Value <> "" Then
lCol = lCol + 1
End If
Loop
End Sub

TLP
08-30-2013, 08:39 AM
Excellent. Works perfectly. Thank you!