Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Don't get the Do Loop syntax or something 1

Status
Not open for further replies.

swtrader

IS-IT--Management
Dec 23, 2004
182
US
Here's a portion of my code that I need to loop. Whether I put the "Loop" before or after the "End If", I get the error, "Loop without Do".

Do While rTC > 1
If InStr(StringToSearch, SearchTerm) > 0 Then
'put the Code in the cell to the left of the transaction detail
MsgBox "SearchTermWasFound"
Range("H1").Copy Destination:=Range("B" & rTC)
Range("B" & rTP, "E" & rTP).Copy Destination:=Worksheets("TransactionsSource").Range("B" & rTS, "E" & rTS)
rTC = rTC - 1
Loop
End If

???
 
Hi,

If you structure you BLOCKS, ie Do...Loop, If...Else...End If, the rule is that no structure can break another structure.

So your If...Else...End If structure, must reside TOTALLY within the Do...Loop structure.
Code:
Do While rTC > 1
    If InStr(StringToSearch, SearchTerm) > 0 Then
        'put the Code in the cell to the left of the transaction detail
        MsgBox "SearchTermWasFound"
        Range("H1").Copy Destination:=Range("B" & rTC)
        Range("B" & rTP, "E" & rTP).Copy Destination:=Worksheets("TransactionsSource").Range("B" & rTS, "E" & rTS)
        rTC = rTC - 1
    End If
Loop

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Simple enough. Thanks!

swtrader
-- If you don't know where you're going, you'll always know when you're not there.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top