hansgrandia
Board Regular
- Joined
- Jan 10, 2015
- Messages
- 53
Hello,
I have worked out below standing code, but it's ignoring the AverageIf part of it. What did I do wrong here? The cells (average) remain empty without error message.
Thank you for your help!
Regards,
Hans
Netherlands
.....................
Sub ReturnLeadTime()
Dim Data As Worksheet
Dim Result As Worksheet
Dim GemLT As Range
Dim Customers As Range
Dim y As Long
Dim x As Long
Set Data = Sheets("Blad1")
Set Result = Sheets("Blad2")
Set Customers = Worksheets("Blad1").Range("A2:A51")
Set GemLT = Worksheets("Blad1").Range("E2:E51")
'Subcategories in Column A
Result.Range("A1").Value = "Customer"
Result.Range("B1").Value = "Average"
Result.Range("A2").Value = "4"
Result.Range("A3").Value = "35"
Result.Range("A4").Value = "44"
'Per subcategorie totaal berekenen
For y = 2 To x
If Cells(y, "A") <> "" Then
Cells(y, 2).Value = WorksheetFunction.AverageIf(Customers, Range("A" & y), GemLT)
End If
Next y
End Sub
I have worked out below standing code, but it's ignoring the AverageIf part of it. What did I do wrong here? The cells (average) remain empty without error message.
Thank you for your help!
Regards,
Hans
Netherlands
.....................
Sub ReturnLeadTime()
Dim Data As Worksheet
Dim Result As Worksheet
Dim GemLT As Range
Dim Customers As Range
Dim y As Long
Dim x As Long
Set Data = Sheets("Blad1")
Set Result = Sheets("Blad2")
Set Customers = Worksheets("Blad1").Range("A2:A51")
Set GemLT = Worksheets("Blad1").Range("E2:E51")
'Subcategories in Column A
Result.Range("A1").Value = "Customer"
Result.Range("B1").Value = "Average"
Result.Range("A2").Value = "4"
Result.Range("A3").Value = "35"
Result.Range("A4").Value = "44"
'Per subcategorie totaal berekenen
For y = 2 To x
If Cells(y, "A") <> "" Then
Cells(y, 2).Value = WorksheetFunction.AverageIf(Customers, Range("A" & y), GemLT)
End If
Next y
End Sub