![]() |
repeat macro for all rows
I have a macro that copies/pastes row data into a form then prints the form.
How do I get the macro to repeat for all rows in the table? TIA |
repeat macro for all rows
Rick,
Post your code.... HTH, Bernie MS Excel MVP "Rick Billingsley" wrote in message ... I have a macro that copies/pastes row data into a form then prints the form. How do I get the macro to repeat for all rows in the table? TIA |
repeat macro for all rows
Sub Populate2005Data() ' ' Populate2005Data Macro ' Macro recorded 11/16/2005 by Rick Billingsley ' ' Sheets("2005 elections").Select Range("A18").Select Selection.Copy Sheets("Side One").Select ActiveSheet.Paste Sheets("2005 elections").Select Range("B18").Select Application.CutCopyMode = False Selection.Copy Sheets("Side One").Select Range("G6:I6").Select ActiveSheet.Paste Sheets("2005 elections").Select Range("L18").Select Application.CutCopyMode = False Selection.Copy Sheets("Side One").Select Range("E14:H14").Select ActiveSheet.Paste Sheets("2005 elections").Select Range("M18").Select Application.CutCopyMode = False Selection.Copy Sheets("Side One").Select Range("E15:H15").Select ActiveSheet.Paste Sheets("2005 elections").Select Range("N18").Select Application.CutCopyMode = False Selection.Copy Sheets("Side One").Select Range("E16:H16").Select ActiveSheet.Paste Sheets("2005 elections").Select Range("O18").Select Application.CutCopyMode = False Selection.Copy Sheets("Side One").Select Range("E17:H17").Select ActiveSheet.Paste Sheets("2005 elections").Select Range("P18").Select Application.CutCopyMode = False Selection.Copy Sheets("Side One").Select Range("E18:H18").Select ActiveSheet.Paste Sheets("2005 elections").Select Range("Q18").Select Application.CutCopyMode = False Selection.Copy Sheets("Side One").Select Range("K23").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Sheets("2005 elections").Select Range("R18").Select Application.CutCopyMode = False Selection.Copy Sheets("Side One").Select Range("K24").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Sheets("Side One").Select Range("A6:E6").Select Worksheets("Side One").PrintOut Copies:=1, Collate:=True End Sub "Bernie Deitrick" wrote: Rick, Post your code.... HTH, Bernie MS Excel MVP "Rick Billingsley" wrote in message ... I have a macro that copies/pastes row data into a form then prints the form. How do I get the macro to repeat for all rows in the table? TIA |
repeat macro for all rows
Rick,
Assuming that your data starts in row2, and you want to print out the data from each row (where column A is filled - no empty cells in column A): try the macro below. If you need help modifying it, post back. HTH, Bernie MS Excel MVP Sub Populate2005DataVer2() Dim shtData As Worksheet Dim shtPrintOut As Worksheet Dim myRow As Long Set shtPrintOut = Sheets("Side One") Set shtData = Sheets("2005 elections") For myRow = 2 To shtData.Cells(Rows.Count, 1).End(xlUp).Row shtPrintOut.Range("A6:E6").Value = _ shtData.Range("A" & myRow).Value shtPrintOut.Range("G6:I6").Value = _ shtData.Range("B" & myRow).Value shtPrintOut.Range("E14:H14").Value = _ shtData.Range("L" & myRow).Value shtPrintOut.Range("E15:H15").Value = _ shtData.Range("M" & myRow).Value shtPrintOut.Range("E16:H16").Value = _ shtData.Range("N" & myRow).Value shtPrintOut.Range("E17:H17").Value = _ shtData.Range("O" & myRow).Value shtPrintOut.Range("E18:H18").Value = _ shtData.Range("P" & myRow).Value shtPrintOut.Range("K23").Value = _ shtData.Range("Q" & myRow).Value shtPrintOut.Range("K24").Value = _ shtData.Range("R" & myRow).Value shtPrintOut.PrintOut Copies:=1, Collate:=True Next myRow End Sub "Rick Billingsley" wrote in message ... Sub Populate2005Data() ' ' Populate2005Data Macro ' Macro recorded 11/16/2005 by Rick Billingsley ' ' Sheets("2005 elections").Select Range("A18").Select Selection.Copy Sheets("Side One").Select ActiveSheet.Paste Sheets("2005 elections").Select Range("B18").Select Application.CutCopyMode = False Selection.Copy Sheets("Side One").Select Range("G6:I6").Select ActiveSheet.Paste Sheets("2005 elections").Select Range("L18").Select Application.CutCopyMode = False Selection.Copy Sheets("Side One").Select Range("E14:H14").Select ActiveSheet.Paste Sheets("2005 elections").Select Range("M18").Select Application.CutCopyMode = False Selection.Copy Sheets("Side One").Select Range("E15:H15").Select ActiveSheet.Paste Sheets("2005 elections").Select Range("N18").Select Application.CutCopyMode = False Selection.Copy Sheets("Side One").Select Range("E16:H16").Select ActiveSheet.Paste Sheets("2005 elections").Select Range("O18").Select Application.CutCopyMode = False Selection.Copy Sheets("Side One").Select Range("E17:H17").Select ActiveSheet.Paste Sheets("2005 elections").Select Range("P18").Select Application.CutCopyMode = False Selection.Copy Sheets("Side One").Select Range("E18:H18").Select ActiveSheet.Paste Sheets("2005 elections").Select Range("Q18").Select Application.CutCopyMode = False Selection.Copy Sheets("Side One").Select Range("K23").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Sheets("2005 elections").Select Range("R18").Select Application.CutCopyMode = False Selection.Copy Sheets("Side One").Select Range("K24").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Sheets("Side One").Select Range("A6:E6").Select Worksheets("Side One").PrintOut Copies:=1, Collate:=True End Sub "Bernie Deitrick" wrote: Rick, Post your code.... HTH, Bernie MS Excel MVP "Rick Billingsley" wrote in message ... I have a macro that copies/pastes row data into a form then prints the form. How do I get the macro to repeat for all rows in the table? TIA |
All times are GMT +1. The time now is 06:58 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com