Forum Discussion

LGray1380's avatar
LGray1380
Copper Contributor
Oct 04, 2022

Help with Merge and Print

I have a spreadsheet that is used to generate timesheets for our employees, which is Sheet2.  I've linked to our accounting system and populated Sheet1.  This is what I need to happen....for each record in Sheet1 I would like the employees name to appear on the timesheet in Sheet2 and have the timesheet print automatically.  I have no idea how to begin to accomplish this.  Any help would be appreciated.  

5 Replies

  • LGray1380 

    Let's say the employee names are in A2 and down on Sheet1.

    You want the name to appear in C1 on the time sheets.

    Macro:

    Sub PrintTimeSheets()
        Dim w1 As Worksheet
        Dim w2 As Worksheet
        Dim r As Long
        Dim m As Long
        Set w1 = Worksheets("Sheet1")
        Set w2 = Worksheets("Sheet2")
        m = w1.Range("A" & w1.Rows.Count).End(xlUp).Row
        For r = 2 To m
            Application.StatusBar = "Printing " & r - 1 & " of " & m - 1
            w2.Range("C1").Value = w1.Range("A" & r).Value
            w2.PrintOut
        Next r
        Application.StatusBar = False
    End Sub
    • LGray1380's avatar
      LGray1380
      Copper Contributor
      Now I get "Run-time error '1004': Application-defined or object-defined error on row 8 in macro

Resources