'Looping through employee IDs on a separate tab to paste to a cell in a Total Rewards Statement and Create a PDF
Looking to create a macro for what the title says, the employee IDs and the Total rewards statement are on separate tabs.
The total rewards statement is driven by a cell (C9:D9) that houses the unique employee ID
Where have I gone wrong? I am getting a 'variable not defined' compile error for the EmployeeIdRange
Option Explicit
Sub Create_PDFs_Loop()
Dim LastRow As Long
Let LastRow = SSSource.Range("B" & Rows.Count).End(xlUp).Row
Dim i As Long
Dim EEID As Long
Dim FileName As String
'12 indicates row where employee IDs start (B12 in SSSource worksheet)
For i = 12 To LastRow
EmployeeIdRange = Range("B" & i).Value
SSSource.EmployeeIdRange.Value.Copy SSDest.Range("C9:D9")
FileName = ThisWorkbook.Path & "\PDFExport"
ActiveSheet.ExportAsFixedFormat xlTypePDF, FileName
Next i
End Sub
Solved!!
Option Explicit
Sub Create_PDFs_Loop()
Dim FileName As String
Dim Startcell As Long
Let Startcell = 12
'12 indicates row where employee IDs start (B12 in SSSource worksheet)
With Application
.StatusBar = "Running Macro..."
.DisplayAlerts = False
End With
Do Until SSSource.Range("B" & Startcell).Value = ""
SSSource.Range("B" & Startcell).Copy SSDest.Range("C9:D9")
ActiveSheet.ExportAsFixedFormat xlTypePDF, FileName:=ThisWorkbook.Path & "\Total Rewards Statement_" & SSDest.Range("B9").Value
Startcell = Startcell + 1
Loop
With Application
.StatusBar = "Macro Complete"
.StatusBar = ""
.DisplayAlerts = True
End With
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
