Printing sequential numbering in Descending Order

yamato1990

New Member
Joined
Oct 3, 2018
Messages
4
Hello,

I copied macro code from this thread https://www.mrexcel.com/forum/excel-questions/490441-printing-sequential-numbers.html

Code:
Sub PrintJobs()
Dim i As Long, startnum As Long, lastnum As Long


    startnum = Application.InputBox("Enter the first job number to be printed", "Print Job Number", 1, , , , , 1)
    lastnum = Application.InputBox("Enter the last job number to be printed", "Print Job Number", 1, , , , , 1)


    For i = startnum To lastnum
        Range("M2").Value = i
        ActiveWindow.SelectedSheets.PrintOut
    Next
    
    End Sub

it works perfectly fine. but is there a way to make this code to print in descending order, for example (100,99,98,97 and so on).

I've try searching in this forum but cannot find the answer as I am not real VBA proficient, so I am looking for a little help.

Thanks.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Maybe like:

Code:
For i = Application.Max(startnum, lastnum) To Application.Min(startnum, lastnum) Step -1
 
Upvote 0
So you want the same code but just the numbers to descend? Can you try the below
Code:
Sub PrintJobs()
Dim i As Long, startnum As Long, lastnum As Long


    startnum = Application.InputBox("Enter the first job number to be printed", "Print Job Number", 1, , , , , 1)
    lastnum = Application.InputBox("Enter the last job number to be printed", "Print Job Number", 1, , , , , 1)


    For i = lastnum to startnum Step-1

        Range("M2").Value = i
        ActiveWindow.SelectedSheets.PrintOut
    Next
    
    End Sub
 
Last edited:
Upvote 0
I've tried both code given and its works fine. Marvelous. although I dont understand the different between Barryl's and Steve's code, or maybe it has same meaning...

well anyway...thanks both of you. :beerchug:
 
Upvote 0
Here is a non-looping macro that you can also try...
Code:
[table="width: 500"]
[tr]
	[td]Sub DescendingSequentialNumbers()
  Dim StartNum As Long, LastNum As Long
  StartNum = Application.InputBox("Enter the first job number to be printed", "Print Job Number", 1, , , , , 1)
  LastNum = Application.InputBox("Enter the last job number to be printed", "Print Job Number", 1, , , , , 1)
  Range("M2").Resize(StartNum - LastNum + 1) = Evaluate(StartNum + LastNum & "-ROW(" & StartNum & ":" & LastNum & ")")
End Sub[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
I tried print from number 111 to 120,
so I put start number as 111 and last number 120, and thats the way I use with my current macro.
 
Upvote 0
I tried print from number 111 to 120,
so I put start number as 111 and last number 120, and thats the way I use with my current macro.

I thought you wanted to list the numbers in descending order? If so, your starting number is the larger number (the first one to be printed) and your last number is the smaller number (the last one to be printed).
 
Upvote 0
Rick, I think that you have missed that the OP wants to put the first number in M2 (& presumably the sheet recalculates something based on that) & then prints the sheet. Then the next number is placed in M2 (not M3) & the sheet printed out etc.
That is what the original code did, and the two codes accepted as working do.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

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