error object required to use function average

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,431
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
hello
I try using average function but it gives object error in this line
VBA Code:
Set myRangeC1 = Worksheets("Sheet1").Range("G2").Value
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?
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
 
@GWteB this is what I got based on the code . the same values in column C for different values in column B
1 AVERAGE.xlsx
BCDEFG
1NUMAVERCONDITION
254223,3353
37,55223,335
456,62223,335
563,63223,335
670,64223,335
777,65223,335
884,66223,335
991,67223,335
1098,68223,335
11105,69223,335
12112,70223,335
Sheet1

and should change
VBA Code:
Range("G" & i).Value
to
VBA Code:
Range("G2").Value
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
I see ... No offence intended, but that makes no sense to me since the results will always be the same (so there's also no loop needed).
You're wanting to get the average of a range consisting of multiple cells. If you divide the outcome with a certain value, you can do that twice or 1,000 times, you're always getting the same result.

EDIT: responding on post #21
 
Upvote 0
Upvote 0
@GWteB
but that makes no sense to me
also @Fluff said it . I thought the result could be different . after what you said and @Fluff I will satisfy so .

my apologies if this thread is not sense from the beginning .

thanks for your guiding and advices .
 
Upvote 0
You are welcome and thanks for letting us know (y)
 
Upvote 0

Forum statistics

Threads
1,215,793
Messages
6,126,936
Members
449,349
Latest member
Omer Lutfu Neziroglu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top