Do until Last row - skipping all the was to until withough running code in between

confused in Frankfurt

Board Regular
Joined
Oct 11, 2010
Messages
53
Hi there,
I have a loop which is skipping from the do until to the end without running through the code in between.

Can someone see why it is not working?

Dim LastRow As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, "a").End(xlUp).Row
End With

Do Until LastRow (LastRow=70)

'Open Template Workbooks
Template.Open
......
......
......
Loop

when I use the debugger I get to the line do until and it skips directly to the end of code after loop
Regards
Sarah
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi,
just need an index to check against your lastrow variable

couple of ways maybe:

Code:
Dim LastRow As Long, r As Long
    With ActiveSheet
        LastRow = .Cells(.Rows.Count, "a").End(xlUp).Row
    End With


    'For Next loop
    For r = 1 To LastRow


        'Open Template Workbooks
        'Template.Open


        MsgBox r
    Next


    'Do Loop
    r = 1
    Do Until r = LastRow


        'Open Template Workbooks
        'Template.Open
        MsgBox r
        r = r + 1
    Loop

Hope Helpful

Dave
 
Upvote 0
Hi Dave, just so I understand correctly - do I have the whole thread from my code which is to be repeated in between For r = 1 to LastRow & MsgBox r and also between Do until r = LastRow & MsgBox r .....
Regards
Sarah
 
Upvote 0
Hi Sara,
example just showed two ways you could do what you want - just pick one the suits your project need.

Dave
 
Upvote 0
OK Dave, thanks but what is the use of the message box? Basically I am filling individual results sheets per RSM from a master sheet (results in rows) to be copy pasted into template until sheet finished and then move to next row and new template. I want it to do until loop untill it gets to the last row in the master sheet. I want it to do this without any intervention from anyone during the process. At the moment a box is popping up with the number 1 - 70 having to click away 69 times.
regards
Sarah
 
Upvote 0
Hi Sarah,
that was put in just to show you what was happening at each Iteration of the loop. You can delete it.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top