Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 111
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,124
Default do while loop problem

I don't understand it either, especially the part about range(am1) but try

Sub loopthrough()
Dim C As Range
for each c in range("t618:t1387")
If C.Value = "Karlan-Gine" and Range("AM1").Value 0 Then
C.Offset(0, 15).Value = "WBK0000"
C.Offset(0, 16).Value = C.Offset(0, 6)
End If
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"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


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,934
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find loop doesn't loop JSnow Excel Discussion (Misc queries) 2 June 24th 09 08:28 PM
loop problem teepee[_3_] Excel Discussion (Misc queries) 3 December 31st 08 11:09 AM
Does loop function cause this problem? Eric Excel Worksheet Functions 3 July 1st 07 01:40 PM
Using a for loop Jeff Excel Discussion (Misc queries) 1 November 8th 06 09:27 PM
Find and Copy loop problem BillyJ Excel Discussion (Misc queries) 3 November 2nd 05 07:16 PM


All times are GMT +1. The time now is 09:56 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"