INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Compile Error: Next without For

Compile Error: Next without For

(OP)

CODE -->

Sub MUFS_Scrubbing()
      
      
Dim Sessions As Object
Dim System As Object



Set System = GetObject("", "Extra.system") ' Gets the system object
If (System Is Nothing) Then
    MsgBox "Could not create the EXTRA System object.  Stopping macro playback."
Stop
End If

Set Sessions = System.Sessions

If (Sessions Is Nothing) Then
    MsgBox "Could not create the EXTRA System object.  Stopping macro playback."
Stop
End If

' Set the default wait timeout value
    g_HostSettleTime = 1      ' milliseconds
    OldSystemTimeout& = System.Timeoutvalue
    If (g_HostSettleTime > OldSystemTimeout) Then
        System.Timeoutvalue = g_HostSettleTime
    End If
    
    
'--------------------------------------------------------------------
'Get the necessary Session Object
Dim Sess0 As Object
Set Sess0 = System.ActiveSession
If (Sess0 Is Nothing) Then
MsgBox "Could not create the Session object. Stopping macro playback."
Stop
End If
If Not Sess0.Visible Then Sess0.Visible = True
Sess0.screen.WaitHostQuiet (g_HostSettleTime)

 
'Start the Loop

 Dim Row As Long
 
    
    With Worksheets("MUFS Scrub")
        
    
    End With
    
    LastRow = ActiveSheet.UsedRange.Rows.Count
    
    For Row = 2 To LastRow
    
        
              
            Do
                Sess0.screen.SendKeys ("<PF11>")
                Sess0.screen.WaitHostQuiet (g_HostSettleTime)
                Sess0.screen.SendKeys ("21")
                Sess0.screen.WaitHostQuiet (g_HostSettleTime)
                Sess0.screen.MoveTo 6, 19
                Sess0.screen.PutString Trim(Cells(Row, 1)), 6, 19
                Sess0.screen.SendKeys ("<tab>")
                Sess0.screen.MoveTo 6, 25
                Sess0.screen.PutString Trim(Cells(Row, 2)), , 6, 25
                Sess0.screen.SendKeys ("<tab>")
                Sess0.screen.MoveTo 6, 36
                Sess0.screen.PutString Trim(Cells(Row, 3)), , 6, 36
                Sess0.screen.SendKeys ("<Enter>")
                Sess0.screen.WaitHostQuiet (g_HostSettleTime)
                Primary_Zip = Sess0.screen.getstring(14, 66, 5)
                Cells(Row, 11).Value = Primary_Zip
           
        
    Row = Row + 1
    
    Next Row
        
    Loop
                    
    
          
End Sub 

I am relatively new to writing macros in Excel. I am not sure why I am receiving the compile error "Next without For". Eventually, there will be more steps in the looped process, not just pulling a zip code. However, I wanted to get the look-up code all set first. The code works except for the loop. Without the "Next Row", it looks up the first record, pulls back the zip code and continuously loops through the first record (obviously because it's not going to the next row on the sheet).

Any assistance will be appreciated.

RE: Compile Error: Next without For

It pays to indent your code so you can see what's going on.

CODE

For Row = 2 To LastRow
    Do
        ....           
        Row = Row + 1
    Next Row
Loop 

for every For you need corresponding Next
for every Do you need corresponding Loop
but you cannot do what you did (in RED)

CODE

For Row = 2 To LastRow
    Do
        ....           
        Row = Row + 1
    Loop
Next Row  

But your Do - Loop does not have a "way out"

Have fun.

---- Andy

There is a great need for a sarcasm font.

RE: Compile Error: Next without For

(OP)
Perfect, Thanks!

pc2

RE: Compile Error: Next without For

Hi,

Your loops cannot overlap. Therefore, your Do...Loop MUST br within the For...Next loop or else TILT!

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close