Hi all,
I am trying to get the macros to populate Cells(7, Column) with total hours worked by the contractor {sum value of number of (D x 12 +N x 12)} for each day from specified Start date to End date( based on Cells(5, Column) dates)
Would really appreciate if you could please help me on with this.
Thank you.
Workbook name: Roster-2021
Worksheet2 name: Summary
Cell ‘A7’ content is Contractor
Worksheet3 name: Roster
Range("D3:D200") has the following details: Permanent Employee, Temporary Employee and contractor
Range("F1:PA1") has dates from 01- January-2021 to 31-December-2021
Range("F4:PA200") has D and N. (D is Day shift and N is Night Shift)
The following code works fine:
Cells(5, Column) = StartD + Column - 3
Cells(6, Column) = Day(StartD + Column - 3)
Countifs code seems incorrect.
VBA Code:
I am trying to get the macros to populate Cells(7, Column) with total hours worked by the contractor {sum value of number of (D x 12 +N x 12)} for each day from specified Start date to End date( based on Cells(5, Column) dates)
Would really appreciate if you could please help me on with this.
Thank you.
Workbook name: Roster-2021
Worksheet2 name: Summary
Cell ‘A7’ content is Contractor
Worksheet3 name: Roster
Range("D3:D200") has the following details: Permanent Employee, Temporary Employee and contractor
Range("F1:PA1") has dates from 01- January-2021 to 31-December-2021
Range("F4:PA200") has D and N. (D is Day shift and N is Night Shift)
The following code works fine:
Cells(5, Column) = StartD + Column - 3
Cells(6, Column) = Day(StartD + Column - 3)
Countifs code seems incorrect.
VBA Code:
VBA Code:
Private Sub CommandButton3_Click()
Application.ScreenUpdating = False
If CDate(TextBox2.Value) < CDate(TextBox1.Value) Then
MsgBox "Invalid entry! Start date must be < than End Date."
End If
Dim StartD As Date, EndD As Date
StartD = TextBox1.Value
EndD = TextBox2.Value
For Column = 3 To EndD - StartD + 3
Cells(5, Column) = StartD + Column - 3
Cells(6, Column) = Day(StartD + Column - 3)
Dim Con As String
Dim she2 As Worksheet
Dim she3 As Worksheet
Dim refD As Date
refD = StartD + Column - 3
Con = Range("A7").Text
she2 = Worksheets("Summary")
she3 = Worksheets("Roster")
she2.Cells(7, Column) = Application.Worksheet.CountIfs(she3!Range("D3:D200"), she2!Con, she3!Range("F1:PA1"), she2!refD, she3!Range("F4:PA200"), "D") + Application.Worksheet.CountIfs(she3!Range("D3:D200"), she2!Con, she3!Range("F1:PA1"), she2!refD, she3!Range("F4:PA200"), "N")
Next Column
Application.ScreenUpdating = True
End Sub
Last edited by a moderator: