Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Issue with Do Loop
Hi - I'm having trouble understanding why the loop below is failing -- when I
execute the code I get the following error: "Compile error: Loop without Do". Any help is appreciated!! The code is below: Sub thirdlevel() Dim thirdvar 'variable for "3rd Level Groundwater" sheet Dim copyvar 'variable for "Copy of Data for Graphs" sheet 'Checking "3rd Level Groundwater" sheet to see how many previous entries there were Sheets("3rd Level Groundwater (2)").Select Range("E5").Select thirdvar = 0 Do If Len(ActiveCell.Offset(4 * thirdvar, 0)) = 0 Then Exit Do Else thirdvar = thirdvar + 1 Loop End If |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Issue with Do Loop
Hi Pivot,
You need to Place the loop statement after End If: Sub thirdlevel() Dim thirdvar 'variable for "3rd Level 'Groundwater" sheet Dim copyvar 'variable for "Copy of Data 'for Graphs" sheet ' Checking "3rd Level Groundwater" sheet to see ' how many previous entries there were Sheets("3rd Level Groundwater (2)").Select Range("E5").Select thirdvar = 0 Do If Len(ActiveCell.Offset(4 * thirdvar, 0)) = 0 Then Exit Do Else thirdvar = thirdvar + 1 End If Loop End Sub --- Regards, Norman "Linking to specific cells in pivot table" crosoft.com wrote in message ... Hi - I'm having trouble understanding why the loop below is failing -- when I execute the code I get the following error: "Compile error: Loop without Do". Any help is appreciated!! The code is below: Sub thirdlevel() Dim thirdvar 'variable for "3rd Level Groundwater" sheet Dim copyvar 'variable for "Copy of Data for Graphs" sheet 'Checking "3rd Level Groundwater" sheet to see how many previous entries there were Sheets("3rd Level Groundwater (2)").Select Range("E5").Select thirdvar = 0 Do If Len(ActiveCell.Offset(4 * thirdvar, 0)) = 0 Then Exit Do Else thirdvar = thirdvar + 1 Loop End If |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Issue with Do Loop
Control structures like Do...Loop and If Then...Else...End If must be
nested - completely enclosed by other control structures. So you could use: Do If Len(ActiveCell.Offset(4 * thirdvar, 0)) = 0 Then Exit Do Else thirdvar = thirdvar + 1 End If Loop But there's really no reason to use the Exit Do. Try: Do Until Len(ActiveCell.Offset(4 * thirdvar, 0)) = 0 thirdvar = thirdvar + 1 Loop In article , "Linking to specific cells in pivot table" crosoft.com wrote: Hi - I'm having trouble understanding why the loop below is failing -- when I execute the code I get the following error: "Compile error: Loop without Do". Any help is appreciated!! The code is below: Sub thirdlevel() Dim thirdvar 'variable for "3rd Level Groundwater" sheet Dim copyvar 'variable for "Copy of Data for Graphs" sheet 'Checking "3rd Level Groundwater" sheet to see how many previous entries there were Sheets("3rd Level Groundwater (2)").Select Range("E5").Select thirdvar = 0 Do If Len(ActiveCell.Offset(4 * thirdvar, 0)) = 0 Then Exit Do Else thirdvar = thirdvar + 1 Loop End If |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Issue with Do Loop
Thanks Norman and JE!! This is what I needed.
"JE McGimpsey" wrote: Control structures like Do...Loop and If Then...Else...End If must be nested - completely enclosed by other control structures. So you could use: Do If Len(ActiveCell.Offset(4 * thirdvar, 0)) = 0 Then Exit Do Else thirdvar = thirdvar + 1 End If Loop But there's really no reason to use the Exit Do. Try: Do Until Len(ActiveCell.Offset(4 * thirdvar, 0)) = 0 thirdvar = thirdvar + 1 Loop In article , "Linking to specific cells in pivot table" crosoft.com wrote: Hi - I'm having trouble understanding why the loop below is failing -- when I execute the code I get the following error: "Compile error: Loop without Do". Any help is appreciated!! The code is below: Sub thirdlevel() Dim thirdvar 'variable for "3rd Level Groundwater" sheet Dim copyvar 'variable for "Copy of Data for Graphs" sheet 'Checking "3rd Level Groundwater" sheet to see how many previous entries there were Sheets("3rd Level Groundwater (2)").Select Range("E5").Select thirdvar = 0 Do If Len(ActiveCell.Offset(4 * thirdvar, 0)) = 0 Then Exit Do Else thirdvar = thirdvar + 1 Loop End If |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Find loop doesn't loop | Excel Discussion (Misc queries) | |||
For next do loop issue | Excel Discussion (Misc queries) | |||
Problem adding charts using Do-Loop Until loop | Excel Programming | |||
Worksheet_Change - loop within a loop | Excel Programming | |||
HELP!!!! Can't stop a loop (NOT an infinite loop) | Excel Programming |