Unable to get average property of Worksheetfunction class

fedds2

New Member
Joined
Dec 30, 2005
Messages
32
I am trying to calculate average and SD from data which has different start points on a worksheet. The data is in column I and the first set starts at I2 and varies where it finishes. The second set starts 6 rows below where the first set ends.

Cells(2,16).Value = Worksheetfunction.Average(Range("I2:I"&NewEnd))
Cells(3,16).Value = Worksheetfunction.StDev(Range("I2:I"&NewEnd))
These two lines work fine

Cells(2,17).Value = Worksheetfunction.Average(Range("I" &RwStart&":I"&NewEnd2))
Cells(3,17).Value = Worksheetfunction.StDev(Range("I"&RwStart&":I"&NewEnd2))

RwStart and NewEnd2 both calculate fine so the problem is in the Range. How should the I be incremented to the correct start point?
What are the rules for the use of " and &?

cheers
Fedds2
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Fedds,

I think you just need to add some spaces inbetween the named range and the & sign (tested)

WorksheetFunction.Average(Range("I" & RwStart & ":I" & NewEnd2))
 
Upvote 0
Hi Jeff,
Thanks for the thoughts. I tried that and it still comes up with the error.
I'm think i'm not defining that first bit correctly ie the Range("I" & RwStart &":I"

Fedds
 
Upvote 0
Arrrrgh - disregard this post as the formula is correct. I am using multiple sheets and on careful checking it is failing on certain sheets becasue of the data. Sorry to waste your time.
 
Upvote 0
Fedds, try stepping through your code using F8 in the VB Editor window, and when it gets to the lines in question (before pressing F8 to go past them) hover your mouse over the two variables RwStart and NewEnd2. Check to make sure they contain values as expected. If not, they're probably setup incorrectly. If you post your full code it might help figure it out, too.
 
Upvote 0

Forum statistics

Threads
1,223,648
Messages
6,173,566
Members
452,520
Latest member
Pingaware

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