View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
straightedge32 straightedge32 is offline
external usenet poster
 
Posts: 5
Default Refer to Column with a variable

I tried doing just what you said, copying the syntax appropriately, but I
just get an error message stating "Run time error 438: Object Doesn't Support
this property or method".

"wrksht" is set to the active worksheet. myRange was declared of type
Range. I don't understand why this wouldn't work. It appears that Average
won't work as a function here. Is that correct?

-M

"atpgroups" wrote:

On 7 May, 22:22, straightedge32
wrote:

Set myRange = wrksht.Range(wrksht.Cells(nCurrRow, 8), wrksht.Cells(nCurrRow,
16)).... etc.

But how do I use this range to calculate a value or put it in a formula?

So I'd like cell (nCurrRow, 17) for instance to be the average of myRange.


wrksht.cells(nCurrRow,17).Value =
Application.WorkSheetFunctions.Average(myRange).Va lue

Should do the trick.

Don't forget the .Value bit. It is not entirely necessary for .Value
as that is the default property, but it makes it clear you are not
trying to redefine a range but instead work on the data in that
range.