MACRO in Excel - print with sequential numbers

3

I have a macro from a few years ago that still works, when I click to print the production orders of my company, I put the start and end number, and the macro prints the OPs with the numbers in order, follows the macro :

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

    startnum = Application.InputBox("Número de inicio", "Imprimir op", 1, , , , , 1)
    lastnum = Application.InputBox("Número de fim", "Imprimir op", 1, , , , , 1)

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

End Sub

(G2 in the code is the cell where the numbers are going to come out) The problem is that I am now changing the ops to leave two per page (leaf economy issue) half of the A4 leaves with one op, the other half leaves another op, I made a mirror in the worksheet for when to change the first op, change also the second, making the two leave on the same sheet, but now my macro does not work as it should, because when the first op is 1, the second one should be 2 and so on, I already tried to put the second op as the value of the first + 1, without success, can help me to change my macro, to G2 quit 1, G32 quit 2, then G2 quit 3, G32 quit 4, and and so on. Thanks

    
asked by anonymous 12.11.2015 / 13:55

1 answer

3

By your explanation I believe that instead of using a For loop it is more appropriate to use a While

Try this example.

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

    startnum = Application.InputBox("Número de inicio", "Imprimir op", 1, , , , , 1)
    lastnum = Application.InputBox("Número de fim", "Imprimir op", 1, , , , , 1)

    i = startnum
    Do While i < lastnum 
        Range("G2").Value = i 
        i = i + 1
        Range("G32").Value = i 
        ActiveWindow.SelectedSheets.PrintOut
        i = i + 1 
    Loop
End Sub
    
12.11.2015 / 17:05