Consulting

Results 1 to 5 of 5

Thread: Why is this loop not working?

  1. #1
    VBAX Regular
    Joined
    Aug 2013
    Posts
    6
    Location

    Why is this loop not working?

    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.

  2. #2
    VBAX Regular raj85's Avatar
    Joined
    Feb 2010
    Location
    Mumbai
    Posts
    34
    Location
    Please provide your code to assist you

  3. #3
    VBAX Regular
    Joined
    Aug 2013
    Posts
    6
    Location
    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

  4. #4
    VBAX Regular raj85's Avatar
    Joined
    Feb 2010
    Location
    Mumbai
    Posts
    34
    Location
    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

  5. #5
    VBAX Regular
    Joined
    Aug 2013
    Posts
    6
    Location
    Excellent. Works perfectly. Thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •