Macro to increase a cell value by 1 and print the page?

vbull

New Member
Joined
Oct 11, 2006
Messages
10
I've got what I think is a fairly solvable problem..but my macro knowledge is limited to recording macros and basic editing. Can anyone help?

I've got a sheet that I need multiple printouts of, each one has a number in a cell which needs incrementing by one. The user will set the range to be printed (on a separate sheet) by typing a value into a cell for the starting value (in this case cell B2 of Sheet1) and the end value in B3 of sheet1 (both inclusive). Run the macro and cell I1 in Sheet4 is set to the starting value, sheet4 is printed and the process is repeated incrementing by 1 untill the end value is reached. (Does that make any sense!?)

I've tried various ways of looping through but keep coming unstuck. Can anyone help?

Cheers

-Mike
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
49,439
Office Version
  1. 365
Platform
  1. Windows
vbull

Welcome to the Mr Excel board!

Untested, but see if this is headed in the right direction.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Increment_and_Print()
    <SPAN style="color:#00007F">Dim</SPAN> StartValue <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> EndValue <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> v <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>
    
    StartValue = Worksheets("Sheet1").Range("B2").Value
    EndValue = Worksheets("Sheet1").Range("B3").Value
    <SPAN style="color:#00007F">For</SPAN> v = StartValue <SPAN style="color:#00007F">To</SPAN> EndValue
        Worksheets("Sheet4").Range("I1").Value = v
        Worksheets("Sheet4").Print
    <SPAN style="color:#00007F">Next</SPAN> v
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 

Forum statistics

Threads
1,136,589
Messages
5,676,679
Members
419,644
Latest member
KeelsM

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
Top