Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
do while loop problem
i have added a do while instruction to my macro
Sub loopthrough() Dim C As Range Dim MyRange As Range Dim myRow As Integer myRow = 1 Set MyRange = Range("t618:t1387") For Each C In MyRange Do Until myRow = 770 If C.Value = "Karlan-Gine" Then If Range("AM1").Value 0 Then C.Offset(0, 15).Value = "WBK0000" C.Offset(0, 16).Value = C.Offset(0, 6) End If ActiveCell.Offset(1, 0).Select myRow = myRow + 1 Loop End Sub -- and get this error message "Compile error.Loop without Do. i have a Do statement at the beginning and don't see what is the problem. thanks in advance BDW |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
do while loop problem
Sorry I am unable to understand your code...but it is definitely missing the
below END IF Next If this post helps click Yes --------------- Jacob Skaria "April" wrote: i have added a do while instruction to my macro Sub loopthrough() Dim C As Range Dim MyRange As Range Dim myRow As Integer myRow = 1 Set MyRange = Range("t618:t1387") For Each C In MyRange Do Until myRow = 770 If C.Value = "Karlan-Gine" Then If Range("AM1").Value 0 Then C.Offset(0, 15).Value = "WBK0000" C.Offset(0, 16).Value = C.Offset(0, 6) End If ActiveCell.Offset(1, 0).Select myRow = myRow + 1 Loop End Sub -- and get this error message "Compile error.Loop without Do. i have a Do statement at the beginning and don't see what is the problem. thanks in advance BDW |
#4
Posted to microsoft.public.excel.misc
|
|||
|
|||
do while loop problem
On Sun, 18 Oct 2009 10:18:01 -0700, April
wrote: i have added a do while instruction to my macro Sub loopthrough() Dim C As Range Dim MyRange As Range Dim myRow As Integer myRow = 1 Set MyRange = Range("t618:t1387") For Each C In MyRange Do Until myRow = 770 If C.Value = "Karlan-Gine" Then If Range("AM1").Value 0 Then C.Offset(0, 15).Value = "WBK0000" C.Offset(0, 16).Value = C.Offset(0, 6) End If ActiveCell.Offset(1, 0).Select myRow = myRow + 1 Loop End Sub -- and get this error message "Compile error.Loop without Do. i have a Do statement at the beginning and don't see what is the problem. thanks in advance BDW You have two IF statements but only one END IF VBA gives that kind of error message in that circumstance. --ron |
#5
Posted to microsoft.public.excel.misc
|
|||
|
|||
do while loop problem
Don't be thrown by the exact wording of that error message... VB will
generate a "without Do", "without Next", "without End If", etc. whenever one or more "blocking" type structures are not complete. By blocking structure I mean code groupings that require a start and end statement such as If..End.If, Do..Loop, For..Next, etc. VB treats all blocks the same (sort of) so that when a closing block statement is missing where several blocking structures are nested within each other, it can't fully trace the logic, so it "guesses" at which closing statement might be missing... sometimes it gets it right, more often than not it doesn't. So don't concentrate on the exact wording rather than the indication that one or more blocking structures are not closed. In your case, there are two closing statements missing... a Next statement to close of the For..Next block you started (that statement goes right before the End Sub statement as your code is constructed... however, the End If statement is harder to place because I don't fully understand what your code is intending to do. I have marked two positions in your code where the End If looks like it would properly go... only **one** of them is correct and you should remove the other one. By the way, if you indent your code for each blocking structure you start and close, it will be easier to see when something is missing. Sub loopthrough() Dim C As Range Dim MyRange As Range Dim myRow As Integer myRow = 1 Set MyRange = Range("t618:t1387") For Each C In MyRange Do Until myRow = 770 If C.Value = "Karlan-Gine" Then If Range("AM1").Value 0 Then C.Offset(0, 15).Value = "WBK0000" C.Offset(0, 16).Value = C.Offset(0, 6) End If == End If ActiveCell.Offset(1, 0).Select == End If myRow = myRow + 1 Loop Next End Sub -- Rick (MVP - Excel) "April" wrote in message ... i have added a do while instruction to my macro Sub loopthrough() Dim C As Range Dim MyRange As Range Dim myRow As Integer myRow = 1 Set MyRange = Range("t618:t1387") For Each C In MyRange Do Until myRow = 770 If C.Value = "Karlan-Gine" Then If Range("AM1").Value 0 Then C.Offset(0, 15).Value = "WBK0000" C.Offset(0, 16).Value = C.Offset(0, 6) End If ActiveCell.Offset(1, 0).Select myRow = myRow + 1 Loop End Sub -- and get this error message "Compile error.Loop without Do. i have a Do statement at the beginning and don't see what is the problem. thanks in advance BDW |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Find loop doesn't loop | Excel Discussion (Misc queries) | |||
loop problem | Excel Discussion (Misc queries) | |||
Does loop function cause this problem? | Excel Worksheet Functions | |||
Using a for loop | Excel Discussion (Misc queries) | |||
Find and Copy loop problem | Excel Discussion (Misc queries) |