Hello ! =)
I have 2 sheets: “Sheet1” and “ALERT”.
On ALERT, I have 2 column “A” and “B”. “A” contains dates and “B” contains variables (CCC, DDD…).
On Sheet1 I have a table with 2 entries :
I tried to write the code, but I’m stuck with “For Each”, because it’s not possible to settle 2 For Each condition.
Public Sub AMCperSOEID()
Set SOEID = Range(Worksheets("Alert").Range("B2"), Worksheets("Alert").Range("B2").End(xlDown))
Set DATES = Range(Worksheets("Alert").Range("A2"), Worksheets("Alert").Range("A2").End(xlDown))
lr = Cells(Rows.Count, 2).End(xlUp).Row - 1
lr2 = Cells(Rows.Count, 3).End(xlToLeft).Column
For i = lr To 4 Step -1
For j = lr2 To 3 Step -1
For Each cell In SOEID
If cell.Value = Range("b" & i).Value Then
For Each cell In DATES
If cell.Value = Range("C" & j).Value Then
Range("c" & i) = WorksheetFunction.CountIfs(SOEID, Range("b" & i), DATES, Range("C" & j))
End If
End If
Next
Next
Next
Next
End Sub
Thank you for your consideration.
Emeric
The table I want to fill looks like that:
<tbody>
</tbody>
I have 2 sheets: “Sheet1” and “ALERT”.
On ALERT, I have 2 column “A” and “B”. “A” contains dates and “B” contains variables (CCC, DDD…).
On Sheet1 I have a table with 2 entries :
- From B4 to B12, I have all the unique variables from “B” in ALERT
- From C3 to AF3, I have all the unique dates from “A” in ALERT
I tried to write the code, but I’m stuck with “For Each”, because it’s not possible to settle 2 For Each condition.
Public Sub AMCperSOEID()
Set SOEID = Range(Worksheets("Alert").Range("B2"), Worksheets("Alert").Range("B2").End(xlDown))
Set DATES = Range(Worksheets("Alert").Range("A2"), Worksheets("Alert").Range("A2").End(xlDown))
lr = Cells(Rows.Count, 2).End(xlUp).Row - 1
lr2 = Cells(Rows.Count, 3).End(xlToLeft).Column
For i = lr To 4 Step -1
For j = lr2 To 3 Step -1
For Each cell In SOEID
If cell.Value = Range("b" & i).Value Then
For Each cell In DATES
If cell.Value = Range("C" & j).Value Then
Range("c" & i) = WorksheetFunction.CountIfs(SOEID, Range("b" & i), DATES, Range("C" & j))
End If
End If
Next
Next
Next
Next
End Sub
Thank you for your consideration.
Emeric
The table I want to fill looks like that:
Count | Labels | |||
Row labels | 7/3/2017 | 7/4/2017 | 7/5/2017 | |
AAA | ||||
BBB | ||||
CCC | ||||
DDD | ||||
EEE | ||||
FFF | ||||
GGG | ||||
HHH | ||||
III | ||||
Grand Total |
<tbody>
</tbody>