Hi,
Think i have an object issue below as the loop code previously worked. i've attached a word document showing the screen print and have scoured the internet but simply cannot remove the error
The CurrentMth Value shows up as teh correct string when i hover above it.
Any pointers appreciated
Sub AddOvertimeInfo()
' Add the overtime hours worked in the relevant month to table for payroll submission
Dim CurrentMth As String
CurrentMth = ActiveWorkbook.Sheets("Data Sheet").Range("C3").Value
Dim TargetWS As Worksheet
TargetWS = ActiveWorkbook.Sheets(CurrentMth)
Dim ExportWS As Worksheet
ExportWS = ActiveWorkbook.Sheets("Export LLR") ' may be able to make this more flexible
Dim EmployeeName As Range
EmployeeName = TargetWS.Rows("2:2") ' may be able to make this more flexible
Dim TotalOvertime As Range
TotalOvertime = TargetWS.Rows("37:37") ' may be able to make this more flexible
Dim TotalOnCallHours As Range
TotalOnCallHours = TargetWS.Rows("40:40") ' may be able to make this more flexible
Dim EmpNme As String
Dim Counter As Integer
Dim LastRow As Long
' this is the loop for adding the overtime hours & on call days
Counter = 5 ' this is the starting line in the export sheet
LastRow = WorksheetFunction.Match("Total", ExportWS.Columns("A:A"), 0)
Do
EmpNme = Cells(Counter, "B") & " " & Cells(Counter, "C")
ExportWS.Cells(Counter, "H").Value = Application.WorksheetFunction.SumIf(EmployeeName, EmpNme, TotalOvertime)
ExportWS.Cells(Counter, "J").Value = Application.WorksheetFunction.SumIf(EmployeeName, EmpNme, TotalOnCallHours)
Counter = Counter + 1
Loop Until Counter = LastRow
End Sub
Bookmarks