MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Looping through rows of data (continued)


Posted by Matthew Halliday on December 18, 2001 7:35 AM

OK. So I've changed it, and hey... it works.

Except now it stops at - Sheets("Data").Cells(counter, 4).Select, with error 1004. DO I have to re-initialise the counter - can't see why? Sorry if this seems dumb - I've not done a huge amount of Excel VBA - but it is increasing.

Sub PrintForm()

'Step through rows of data one at a time

Dim EndRow, counter As Integer
Sheets("Data").Select
EndRow = Range("A65536").End(xlUp).Row

For counter = 1 To EndRow

Sheets("Data").Cells(counter, 1).Select
Selection.copy
Application.Goto Reference:="NAME"
ActiveSheet.Paste

Sheets("Data").Cells(counter, 4).Select
Selection.copy
Application.Goto Reference:="NI"
ActiveSheet.Paste

Sheets("Data").Cells(counter, 8).Select
Selection.copy
Application.Goto Reference:="CODE"
ActiveSheet.Paste

Sheets("Data").Cells(counter, 11).Select
Selection.copy
Application.Goto Reference:="ACCOUNT"
Selection.PasteSpecial Paste:=xlValues

ActiveWindow.SelectedSheets.PrintOut Copies:=1

MsgBox ("Continue")

Next counter

End Sub


Posted by MattH on December 18, 2001 8:01 AM

S'ok - I think I've got it sorted. Thanks everyone