Hello community
Can you please help me figure out how to write a user defined function for GeomeanIF that is similar to AVERAGEIF function, I want to write a Macro similar the module below but for GEOMEAN:
>>> use code - tags <<<
Can you please help me figure out how to write a user defined function for GeomeanIF that is similar to AVERAGEIF function, I want to write a Macro similar the module below but for GEOMEAN:
>>> use code - tags <<<
Code:
Sub Average1()
' To calculate arithmetic average of the relatives and put it row by row
'
Dim ws As Worksheet
Dim lastrow As Long
Set ws = Sheets("Sheet1") ' Change to your sheet
With ws
lastrow = .Range("C" & .Rows.Count).End(xlUp).Row
With .Range("A1:I" & lastrow)
.Offset(, 9).Value = .Value
End With
With .Range("G2:I" & lastrow)
.Offset(, 9).FormulaR1C1 = "=AVERAGEIF(C1,RC1,C[-9])"
.Offset(, 9).Value = .Offset(, 9).Value
End With
'.Range("F1:I" & lastrow).RemoveDuplicates 1, xlYes
'Range("F:G").Copy Worksheets("Sheet2").Range("F:G")
' Worksheets("Sheet2").Range("A:D") = Range("F:I").Value
End With
End Sub
Last edited by a moderator: