Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,670
Default Math calculations in VBA

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default Math calculations in VBA

Hi Eric,

ActiveCell.FormulaR1C1 = "AVERAGE("&FirstAdress&","&LastAdress&")"

--

Kind Regards,

Niek Otten

Microsoft MVP - Excel


"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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Math calculations in VBA

Eric,

If First address and lastaddress have an A1 style string, you need

ActiveCell.Formula = "AVERAGE("&FirstAdress&","&LastAdress&")"
--
HTH

-------

Bob Phillips
"Niek Otten" wrote in message
...
Hi Eric,

ActiveCell.FormulaR1C1 = "AVERAGE("&FirstAdress&","&LastAdress&")"

--

Kind Regards,

Niek Otten

Microsoft MVP - Excel


"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





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Math calculations in VBA

Can you show how this would work using integer values for row, column to
reference the cell range for the calculation?

TIA,

Tim

"Bob Phillips" wrote:

Eric,

If First address and lastaddress have an A1 style string, you need

ActiveCell.Formula = "AVERAGE("&FirstAdress&","&LastAdress&")"
--
HTH

-------

Bob Phillips
"Niek Otten" wrote in message
...
Hi Eric,

ActiveCell.FormulaR1C1 = "AVERAGE("&FirstAdress&","&LastAdress&")"

--

Kind Regards,

Niek Otten

Microsoft MVP - Excel


"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






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,670
Default Math calculations in VBA

Hi thanks for you input, unfortunately I'm still getting this error:

Compile Error: Expected end of statement. and the "," area is
highlighted. I've tried

ActiveCell.FormulaR1C1 = "=AVERAGE("&FirstOccurrence&","&LastOccurrence &")"
ActiveCell.FormulaR1C1 = "AVERAGE("&FirstOccurrence&","&LastOccurrence& ")"
ActiveCell.FormulaR1C1 = "=AVERAGE("&FirstOccurrence&":"&LastOccurrence &")"

I keep getting the same error, what am I doing wrong? Thanks again,

Eric


"Niek Otten" wrote:

Hi Eric,

ActiveCell.FormulaR1C1 = "AVERAGE("&FirstAdress&","&LastAdress&")"

--

Kind Regards,

Niek Otten

Microsoft MVP - Excel


"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






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Math calculations in VBA

You need to put in spaces as I showed you in my post.

ActiveCell.FormulaR1C1 = "=AVERAGE(" & _
FirstOccurrence & "," & LastOccurrence & ")"



--
Regards,
Tom Ogilvy

"Eric" wrote in message
...
Hi thanks for you input, unfortunately I'm still getting this error:

Compile Error: Expected end of statement. and the "," area is
highlighted. I've tried

ActiveCell.FormulaR1C1 =

"=AVERAGE("&FirstOccurrence&","&LastOccurrence &")"
ActiveCell.FormulaR1C1 = "AVERAGE("&FirstOccurrence&","&LastOccurrence& ")"
ActiveCell.FormulaR1C1 =

"=AVERAGE("&FirstOccurrence&":"&LastOccurrence &")"

I keep getting the same error, what am I doing wrong? Thanks again,

Eric


"Niek Otten" wrote:

Hi Eric,

ActiveCell.FormulaR1C1 = "AVERAGE("&FirstAdress&","&LastAdress&")"

--

Kind Regards,

Niek Otten

Microsoft MVP - Excel


"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






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,670
Default Math calculations in VBA

Thanks so much! Syntax is evil ;-)

"Tom Ogilvy" wrote:

You need to put in spaces as I showed you in my post.

ActiveCell.FormulaR1C1 = "=AVERAGE(" & _
FirstOccurrence & "," & LastOccurrence & ")"



--
Regards,
Tom Ogilvy

"Eric" wrote in message
...
Hi thanks for you input, unfortunately I'm still getting this error:

Compile Error: Expected end of statement. and the "," area is
highlighted. I've tried

ActiveCell.FormulaR1C1 =

"=AVERAGE("&FirstOccurrence&","&LastOccurrence &")"
ActiveCell.FormulaR1C1 = "AVERAGE("&FirstOccurrence&","&LastOccurrence& ")"
ActiveCell.FormulaR1C1 =

"=AVERAGE("&FirstOccurrence&":"&LastOccurrence &")"

I keep getting the same error, what am I doing wrong? Thanks again,

Eric


"Niek Otten" wrote:

Hi Eric,

ActiveCell.FormulaR1C1 = "AVERAGE("&FirstAdress&","&LastAdress&")"

--

Kind Regards,

Niek Otten

Microsoft MVP - Excel


"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






  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Math calculations in VBA

Eric,

check m y response too

--
HTH

Bob Phillips

"Eric" wrote in message
...
Hi thanks for you input, unfortunately I'm still getting this error:

Compile Error: Expected end of statement. and the "," area is
highlighted. I've tried

ActiveCell.FormulaR1C1 =

"=AVERAGE("&FirstOccurrence&","&LastOccurrence &")"
ActiveCell.FormulaR1C1 = "AVERAGE("&FirstOccurrence&","&LastOccurrence& ")"
ActiveCell.FormulaR1C1 =

"=AVERAGE("&FirstOccurrence&":"&LastOccurrence &")"

I keep getting the same error, what am I doing wrong? Thanks again,

Eric


"Niek Otten" wrote:

Hi Eric,

ActiveCell.FormulaR1C1 = "AVERAGE("&FirstAdress&","&LastAdress&")"

--

Kind Regards,

Niek Otten

Microsoft MVP - Excel


"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






  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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



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
math DeAnna Ramirez Excel Worksheet Functions 2 June 7th 07 11:42 PM
Math help LatinAviation Excel Discussion (Misc queries) 4 August 18th 06 09:10 PM
Math Curtis Excel Discussion (Misc queries) 0 July 24th 06 11:34 PM
Need some math help Mike K Excel Discussion (Misc queries) 1 February 20th 06 09:16 PM
math Bill Excel Discussion (Misc queries) 3 August 11th 05 11:21 PM


All times are GMT +1. The time now is 06:40 AM.

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

About Us

"It's about Microsoft Excel"