Looping

M

Maggie

I need some help ....
How can I loop the following cammand

ActiveCell.FormulaR1C1 = "Value"
Range("N2").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Range("N1").Select
 
S

Sean Timmons

Depends on what you want to do with your loop. If you just want to do it 5
times regardless, you can do a couple things. Easiest would be change
printout copies:= to 5. :)

If you want to change a value, say your "Value", then something like

For i = 1 to 10
ActiveCell.FormulaR1C1 = "Value"
Range("N2").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Range("N1").Select
"value" = "Value+1
Next i

Course, you may want to do other calculations, so it depends.

BTW, looks like your range.Select lines aren't needed.
 
M

Maggie

TY Sean ... but it's not doing what i want, I'll to give more details....

The value in Cell N1 needs to change after every print.
Example:
My first print will have the value of 1 in cell N1, then macro command to
print page, then I automatically want the value in cell N1 to change to 2
then print, and so on until let's say page 30.

Does this make sense???

Maggie
 
S

Sean Timmons

K.. so..

For i = 1 to 10
Range("N1").Value = i
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Next i
 
S

Sean Timmons

oh, and change the For i = 1 to 10 to whatever you want.. 1 to 30, say.

Or, you can do an input box to select # of pages, then do i = 1 to result.
 
M

Maggie

That's great .. works like a charm.

Just another question on this .... do I need to make any changes to my macro
if there are several vlookup formulas in the worcheet that are linked to the
value of cell N1 and another datasource?
Would the print command in the macro activate only once all the formulas are
updated or do I need to add a special command in the macro?
 
S

Sean Timmons

Good question. you can test for yourself by starting with i = 1 to 2 and see
what happens.

You can add a line item

Calculate prior to the print command.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top