Hi All,
I am having trouble ignoring certain rows in loop for a sumif calculation which populates a table of hours worked based on source data.
The below table is in the worksheet "HrsByDisc" and the data that it using is in the
A B C D E F G H I J K L
5 Jan-17 Feb-17 Mar-17 Apr-17 May-17 Jun-17 Jul-17 Aug-17 Sep-17
6 X Process 1000
7 Electrical 2000
8 X Civil 3000
9 Piping 4000
10 X Telecoms 5000
I have written the below code which - if I exclude the code in red - will sumif the discipline across all rows and columns. I have added the code in red because I only want to sumif the rows that havw an X in column A, and ignore all of the others, but I can not get it to work.
Can anyone tell me where I am going wrong?
Thanks,
Kind Regards,
Simon
Sub Sumifs()Please Login or Register to view this content.
Dim ws1 As Worksheet, ws2 As Worksheet
Dim lr As Long, lc As Long
Dim rngr As Range, rngc As Range, Cellr As Range, Cellc As Range, rangif As Range
Set ws1 = ThisWorkbook.Sheets("Export")
Set ws2 = ThisWorkbook.Sheets("HrsByDisc")
lr = ws2.Cells(Rows.Count, "C").End(xlUp).Row
lc = ws2.Cells(5, Columns.Count).End(xlToLeft).Column
Set rngr = ws2.Range("c6:C" & lr)
Set rngc = ws2.Range(Cells(5, "D"), Cells(5, lc))
Set rngif = ws2.Range("a6:A")
For Each Cellr In rngr
For Each Cellc In rngc
If rngif = "X" Then
Cells(Cellr.Row, Cellc.Column) = Application.WorksheetFunction.Sumifs(ws1.Range("T:T"), ws1.Range("D:D"), Cellr.Value, ws1.Range("P:P"), Cellc.Value, ws1.Range("C:C"), ws2.Range("Actual"))
Else
Next Cellc
Next Cellr
End Sub[/CODE]Please Login or Register to view this content.
Bookmarks