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
 

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
5,255
Office Version
2013
Platform
Windows
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
 

confused in Frankfurt

Board Regular
Joined
Oct 11, 2010
Messages
53
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
 

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
5,255
Office Version
2013
Platform
Windows
Hi Sara,
example just showed two ways you could do what you want - just pick one the suits your project need.

Dave
 

confused in Frankfurt

Board Regular
Joined
Oct 11, 2010
Messages
53
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
 

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
5,255
Office Version
2013
Platform
Windows
Hi Sarah,
that was put in just to show you what was happening at each Iteration of the loop. You can delete it.
 

Forum statistics

Threads
1,081,795
Messages
5,361,333
Members
400,627
Latest member
Mcomeaux

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top