#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Loop Macro

I have a template that I want to fill in a cell from another worksheet
(project #) and then print the template which fills in other pertenent
information. The project # range is variable. How can I create a loop to
select the first cell, copy and paste to the template, print the template and
then repeat the process until all project #s have been selected? Thanks so
much.

KK
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Loop Macro

Hi KK

Wih this macro I assume that Project# workbook is open, and project# is in
column A starting in row 2. TargetCell is the project# cell in the template.

Sub test()
Dim ProjectWB As Workbook
Set ProjectWB = Workbooks("Project#.xls")
TargetCell = "A1" ' change to suit
ProjectNumCol = "A"
StartRow = 2 ' Assuming headings in row 1
LastRow = ProjectWB.Worksheets("Sheet1"). _
Cells(StartRow, ProjectNumCol).End(xlDown).Row
For r = 1 To LastRow
Range(TargetCell) = ProjectWB.Worksheets _
("Sheet1").Cells(r, ProjectNumCol)
ThisWorkbook.PrintOut
Next
End Sub

Regards,
Per

"KalliKay" skrev i meddelelsen
...
I have a template that I want to fill in a cell from another worksheet
(project #) and then print the template which fills in other pertenent
information. The project # range is variable. How can I create a loop to
select the first cell, copy and paste to the template, print the template
and
then repeat the process until all project #s have been selected? Thanks
so
much.

KK


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Loop Macro

Thanks so much. I used some of your code in combination with some other and
it worked great.

KK

"Per Jessen" wrote:

Hi KK

Wih this macro I assume that Project# workbook is open, and project# is in
column A starting in row 2. TargetCell is the project# cell in the template.

Sub test()
Dim ProjectWB As Workbook
Set ProjectWB = Workbooks("Project#.xls")
TargetCell = "A1" ' change to suit
ProjectNumCol = "A"
StartRow = 2 ' Assuming headings in row 1
LastRow = ProjectWB.Worksheets("Sheet1"). _
Cells(StartRow, ProjectNumCol).End(xlDown).Row
For r = 1 To LastRow
Range(TargetCell) = ProjectWB.Worksheets _
("Sheet1").Cells(r, ProjectNumCol)
ThisWorkbook.PrintOut
Next
End Sub

Regards,
Per

"KalliKay" skrev i meddelelsen
...
I have a template that I want to fill in a cell from another worksheet
(project #) and then print the template which fills in other pertenent
information. The project # range is variable. How can I create a loop to
select the first cell, copy and paste to the template, print the template
and
then repeat the process until all project #s have been selected? Thanks
so
much.

KK



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop Macro Brian Excel Programming 3 June 17th 08 05:20 AM
Help with using a Macro Loop Mark Costello[_2_] Excel Discussion (Misc queries) 5 October 19th 07 02:01 PM
Do until loop with use of another macro in loop The Excelerator Excel Programming 9 February 28th 07 02:28 AM
Macro - Loop or Next Rashid[_2_] Excel Programming 2 April 3rd 06 10:21 PM
macro loop DM Excel Discussion (Misc queries) 1 January 3rd 06 10:46 PM


All times are GMT +1. The time now is 12:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"