ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   "for ... to ..." with input from list (https://www.excelbanter.com/excel-programming/373798-input-list.html)

claudio

"for ... to ..." with input from list
 
I have a list of 30 names. A macro should input the first name into cell A1,
print the spreadsheet, input the second name into A1, print etc.

The list can be either in a spreadsheet or in the VBA code.

I used to copy-paste the following code 30 times and had to replace {name}
each time. What is the more effective way? Thanx in advance!

Range("A1").Select
ActiveCell.FormulaR1C1 = {name}
Range("A2").Select 'to calculate cells again
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True



Bob Phillips

"for ... to ..." with input from list
 
Something like

For i = 1 To 30
Range("A1").Value = Worksheets("Sheet2").Cells(i,"M"(.Value
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Next i

where M1:M30 on sheet2 holds the list of names


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"claudio" wrote in message
...
I have a list of 30 names. A macro should input the first name into cell

A1,
print the spreadsheet, input the second name into A1, print etc.

The list can be either in a spreadsheet or in the VBA code.

I used to copy-paste the following code 30 times and had to replace {name}
each time. What is the more effective way? Thanx in advance!

Range("A1").Select
ActiveCell.FormulaR1C1 = {name}
Range("A2").Select 'to calculate cells again
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True






All times are GMT +1. The time now is 05:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com