Discussion Locked

payroll spreadsheet, loop to print stubs

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Help needed with inserting a print command in a loop to print a pay stub if another employee exists in the register portion of the worksheet. I have the stub set as the print area, and need this to print for each employee.

Thanks in advance

Robert Burge
North Atlantic Petroleum
St. John's, NF

5 replies

by dklippert

Have you though about setting up the paystub form in Word and then doing a Mail Merge?
You could still do queries to print stubs that fit a particular criteria, and the stubs could be formatted more easily.

by robert burge

It's not a formatting issue, all I want is to print multiple stubs within a loop if more than one record exists.

by srobertson

You could try using a "For Each" Loop using your register list as the range. For Example:- (Assumes register list range is in Column B with a header at "B1")

Sub Print_Loop ()

'Variable Declaration
Dim TestCell as Range

'Find End Of List
Range("B1").Select

If Activecell.Offset <> "" then
Selection.End(xlDown).Select
Else
Activecell.Offset (1,0).Select
End If

'Loop for each value in the Test Range
For Each TestCell in Range("B2:B" & Activecell.Row)

'Set changing Register Variable
Range("RegisterVariable").Value = TestCell.Value

'Print Register Stub Sheet
Sheets("PayRollStub").PrintOut

Next TestCell

End Sub

You haven't provided a lot of information to go on so I hope this is sort of what your'e looking for.

Scott.

by srobertson

Sorry,

The line 'If Activecell.Offset <> "" then' should read

'If Activecell.Offset(0,1).Value <> "" then'

Scott.

This discussion is closed to new replies.