Hello, I am trying to use VBA to populate a summary table based on inputs within the "staffing plan" worksheet. Right now, I am using an array formula to populate these hours per resource per month summaries, but it takes FOREVER.
I was wondering if it would be possible to use a regular SUMIF formula instead, but the one thing that would need to happen is that the sum column would need to be dynamic off of the column header. The column headers are in F-Q (there are multiple summary tables on top of each other - 2016 then 2017 then 2018, etc., so the column headers are in multiple rows). I currently reference the column headers with "F$" & N_2 - 1" below which is dragged across to column Q ("Q$" & N_2 - 1").
I'm hoping for something like:
= SUMIFS("dynamic sum column - rows 13:1008", 'Staffing Plan'!$C$13:$C$1008,$A$1,'Staffing Plan'!$L$13:$L$1008,$C" & N_2)
For reference... in column A, Row 1 of each summary table there is a number which determined and inserted the number of rows required for each summary table. So, the column headers are always in row: "N_2" - 1.
I was wondering if it would be possible to use a regular SUMIF formula instead, but the one thing that would need to happen is that the sum column would need to be dynamic off of the column header. The column headers are in F-Q (there are multiple summary tables on top of each other - 2016 then 2017 then 2018, etc., so the column headers are in multiple rows). I currently reference the column headers with "F$" & N_2 - 1" below which is dragged across to column Q ("Q$" & N_2 - 1").
I'm hoping for something like:
= SUMIFS("dynamic sum column - rows 13:1008", 'Staffing Plan'!$C$13:$C$1008,$A$1,'Staffing Plan'!$L$13:$L$1008,$C" & N_2)
For reference... in column A, Row 1 of each summary table there is a number which determined and inserted the number of rows required for each summary table. So, the column headers are always in row: "N_2" - 1.
Code:
Sub Generate_4()
Dim Sh As Worksheet
Dim Source_End_Row_2 As Integer
Dim Insert_Rows_2 As Integer
Dim N2 As Integer
For Each Sh In ActiveWorkbook.Sheets
If Left(Sh.Name, 9) = "Labor BOE" Then
'Populate the "Labor Hours By Resource" summary at WBS Level
Source_End_Row_2 = Sh.Range("T" & Rows.Count).End(xlUp).Row
For N_2 = Source_End_Row_2 To 3 Step -1
Insert_Rows_2 = Sh.Cells(N_2, "A").Value
If Insert_Rows_2 > 0 Then
'MONTH COLUMNS
On Error Resume Next
With Sh.Range("F" & N_2, "Q" & N_2 + Insert_Rows_2)
.Formula = "=SUM(IF('Staffing Plan'!$C$13:$C$1008=$A$1,IF('Staffing Plan'!$L$13:$L$1008=$C" & N_2 & ",IF('Staffing Plan'!$L$13:$FV$13=[U][B]F$" & N_2 - 1 [/B][/U]& ",'Staffing Plan'!$L$13:$FV$1008))))"
.FormulaArray = .FormulaR1C1
.Value = .Value
End With
On Error GoTo 0
End If
Next N_2
End If
Next Sh
End Sub