abdelfattah
Well-known Member
- Joined
- May 3, 2019
- Messages
- 1,448
- Office Version
- 2019
- 2010
- Platform
- Windows
hello
I try using average function but it gives object error in this line
the column B contains values and range G2 also values and the formula should be like this average(B2/G2) and the result should be in column C
any idea to fix it ,please?
I try using average function but it gives object error in this line
VBA Code:
Set myRangeC1 = Worksheets("Sheet1").Range("G2").Value
any idea to fix it ,please?
VBA Code:
Sub Test()
Dim nb_rows As Long
Dim myRangeC, myRangeC1 As Range
Dim i As Long
nb_rows = Range("b" & Rows.Count).End(xlUp).Row
'Change Sheet1 to your sheet name
Set myRangeC = Worksheets("Sheet1").Range("B2:B" & nb_rows)
Set myRangeC1 = Worksheets("Sheet1").Range("G2").Value
For i = 2 To nb_rows
Range("C" & i).Value = Application.WorksheetFunction.Average(myRangeC / myRangeC1)
Next i
End Sub