Do While & Number Advancing

jweese74

New Member
Joined
May 5, 2005
Messages
25
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 2007
Platform
  1. Windows
MrExcel forums to the rescue again - furthermore, I always give full credit back to the forums when folks ask "how did you figure that out!?"

Cell B1 contains a number, we'll say "25";

I would like to increment the number in cell A1, beginning at "1" until it reaches the equivalent of B1 then STOP. Furthermore, with each increment perform another SUB (see my previous post "Conditional Printing" for more information).

Thoughts around this?
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
"See my previous post"

Better to post a link to it than have everyone running round searching for it.

I feel there's more information you need to supply so this is prob not what you want.
But it reflects you're fairly simple description.

Code:
Sub IncCell()
    For i=1 to Cells(1,2)
        Cells(1,1)=i
        Call SUB2
    Next i
End Sub
 
Upvote 0
My apologies for not being specific - I try to keep my requests as simple as possible, forgetting the userbase I'm communicating with who certainly has more ability than myself to understand complex questions.

Our organization tracks form data in an Excel spreadsheet. Each Form could have up to 100 lines of data, or 1 line of data. There could be between 1-100 individual forms as well. On the form itself, Cell H1 contains the total number of forms that need printed, Changing the value in Cell E1 will populate the form with the necessary data then the form is printed using the following Sub (in the thread I was previously referencing)...

Code:
Sub MySetPrintAreaMacro()

    Dim switch As String
    Dim r As Long
    
'   Find first value that indicates the switch
    switch = 1
    
'   Find first instance
    On Error GoTo err_chk
    r = Range("A:A").Find(What:=switch, After:=Range("A1"), LookIn:=xlValues, _
        LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Row
    On Error GoTo 0
        
'   Set print range for columns A-K
    ActiveSheet.PageSetup.PrintArea = "$C$1:$L$" & r - 1
    ActiveSheet.PrintOut
    Exit Sub
    
'   Error handling if it cannot find switch value
err_chk:
    If Err.Number = 91 Then
        MsgBox "Cannot find switch value of " & switch & " in column A"
    Else
        MsgBox Err.Number & ": " & Err.Description
    End If
    
End Sub

What I'm looking for is a way to automatically increment the value of E1 beginning at 1, up to and including the limit value stored in H1 - calling the SUB above with each iteration.

I know there are better ways to do this, and I would have preferred to probably use something different but I'm forced to work with what I'm given.

I hope this explains it a bit more.
 
Upvote 0
That VBA is beyond me I'm afraid.

I certainly appreciate your time and help - most VBA is beyond me, or I assume it is - while I'm able to read an understand it, I just can't write it.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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