Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default How to use Excel formulas in VBA

I would like to know how to use the standard Excel
formulas in VBA. For example, one function that I am
trying to use is the average function. When I record a
macro following the steps to perform this function it
gives me the following:

ActiveCell.FormulaR1C1 = "=AVERAGE(R[-31]C:R[-1]C)"

The catch is that the column I need to average will vary
in size. I can store the size of the column by indexing.
My question is how do I place this variable in the formula
above to calculate the average? Is it possible or is
there another format that must be used? Any help would be
greatly appreciated.

Thanks,
Jeff
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How to use Excel formulas in VBA

Sub tester3()
r1 = 3
r2 = 100
Cells(2, 5).FormulaR1C1 = "=Average(R" & r1 & "C:R" & r2 & "C)"
End Sub

Using absolute references

--
Regards,
Tom Ogilvy


Jeff Armstrong wrote in message
...
I would like to know how to use the standard Excel
formulas in VBA. For example, one function that I am
trying to use is the average function. When I record a
macro following the steps to perform this function it
gives me the following:

ActiveCell.FormulaR1C1 = "=AVERAGE(R[-31]C:R[-1]C)"

The catch is that the column I need to average will vary
in size. I can store the size of the column by indexing.
My question is how do I place this variable in the formula
above to calculate the average? Is it possible or is
there another format that must be used? Any help would be
greatly appreciated.

Thanks,
Jeff



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to use Excel formulas in VBA


try like this

Sub avera()
Ran = Range(Cells(1, 1), Cells(14, 1))
T = Application.WorksheetFunction.Average(Ran)
Cells(15, 1) = T
End Sub


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting # of Formulas in a column with formulas and entered data Brand Excel Worksheet Functions 1 October 10th 09 01:01 PM
ms-excel guidence notes, complete formulas in excel, How to runmacros in Ms excel [email protected] Excel Discussion (Misc queries) 0 June 14th 08 03:19 PM
CELLS NOT CALC FORMULAS - VALUES STAY SME FORMULAS CORRECT?? HELP Sherberg Excel Worksheet Functions 4 September 11th 07 01:34 AM
Copying formulas from Excel 2003 to Excel 2007 [email protected] Excel Discussion (Misc queries) 4 August 9th 07 06:06 PM
Formulas not evaluated, Formulas treated as strings Bob Sullentrup Excel Discussion (Misc queries) 0 November 27th 06 08:01 PM


All times are GMT +1. The time now is 01:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"