sangamk_81
New Member
- Joined
- Jun 13, 2022
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
Dear All,
I am facing the error - Excel Run TIme Error 1004 - Unable to get Averageif Property of Worksheetfunction class in below VBA code.
Request your help.
Sub CaptureSeasonality()
Dim wb As Workbook, ws As Worksheet, LastRow As Long
Set wb = ThisWorkbook
Set ws = wb.Sheets("Calculations")
Worksheets("Calculations").Activate
With Sheets2
LastRow = Cells.CurrentRegion.Rows.Rows.Count
Range("=Calculations!H2").Value = "Seasonality"
Dim rng1 As Range, rng2 As Range
Set rng1 = ws.Range(Cells(7, 3), Cells(17, 3))
Set rng2 = ws.Range(Cells(7, 7), Cells(17, 7))
Dim x As Long
For x = 1 To LastRow
Range("=Calculations!H" & x + 2).Value = Round(WorksheetFunction.AverageIf(rng1, (ws.Cells((x + 2), 3).Value), rng2), 3)
Next
End With
End Sub
I am facing the error - Excel Run TIme Error 1004 - Unable to get Averageif Property of Worksheetfunction class in below VBA code.
Request your help.
Sub CaptureSeasonality()
Dim wb As Workbook, ws As Worksheet, LastRow As Long
Set wb = ThisWorkbook
Set ws = wb.Sheets("Calculations")
Worksheets("Calculations").Activate
With Sheets2
LastRow = Cells.CurrentRegion.Rows.Rows.Count
Range("=Calculations!H2").Value = "Seasonality"
Dim rng1 As Range, rng2 As Range
Set rng1 = ws.Range(Cells(7, 3), Cells(17, 3))
Set rng2 = ws.Range(Cells(7, 7), Cells(17, 7))
Dim x As Long
For x = 1 To LastRow
Range("=Calculations!H" & x + 2).Value = Round(WorksheetFunction.AverageIf(rng1, (ws.Cells((x + 2), 3).Value), rng2), 3)
Next
End With
End Sub