Math calculations in VBA
FirstAdress = "A1"
LastAdress = "A10"
ActiveCell.Formula = "=AVERAGE(" & FirstAdress & "," & LastAdress & ")"
--
Regards,
Tom Ogilvy
"Eric" wrote in message
...
Hi,
I'm trying to write some code to automatically calculate different math
functions based on a set of data. Namely: mean, std dev, and %rsd. The
calculations are based off of data that is imported and contains a
variable
number of entries. The data is initially imported in a big unordered
clump.
I have already written code to sort and then segregate the data into
different groups depending on what it comes from. After this I need to do
these calculations on each group of data. I have accomplished the
grouping
by using looped counters that search for matches and then record the first
and last cell addresses to define the upper and lower limits of each group
ie
A1:A21. This gives me the address locations, stored in variables, of the
data I want to calculate. My problem is all the examples of formula code
in
VBA I have found uses quotes and defined cell addresses to work ie:
ActiveCell.FormulaR1C1 = "=AVERAGE(R[-4]C:R[-1]C)". If I put my variables
in
the equation they are not recognized due to the quotes. Can someone show
me
the syntax to do what I need? I basically would like something like this:
Cells(1, 20).Select
ActiveCell.FormulaR1C1 = AVERAGE(FirstAddress, LastAddress)
where first and last address have stored a location A1 and A19 for
example.
TIA,
Eric
|