Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 217
Default Formula R1C1 in VBA - Strange Results (Dynamic)

Hi,

I have the following code in VBA to give me some variance % results.
Although the rows are always static the columns are not:

ActiveCell.FormulaR1C1 = "=SUM(R[-34]C-R[-17]C)/R[-17]C"
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "=SUM(R[-32]C-R[-15]C)/R[-15]C"
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "=SUM(R[-30]C-R[-13]C)/R[-13]C"

What I want this to do is to start in row 45, in the column i am in (worked
out prior to this in the macro) and put in a formula which basically in Excel
would read:

=SUM(I11-I28)/I28
then down one row
=SUM(I13-I30)/I30
then down one row
=SUM(I15-I32)/I32

This works, but only for the 1st and 3rd formulae, the second one is always
wrong by one row...

Am I doing something majorly wrong here?

Thanks,
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 269
Default Formula R1C1 in VBA - Strange Results (Dynamic)

are you sure the 3rd formula is OK

All three of these formuls seem to be set up to reference the desired ranges
from row 45

45-34=11 45-17=28 Good for row 45 and would be SUM(I11-I28)/I28
45-32=13 45-15=30 Good for row 45 and would be SUM(I13-I30)/I3
To put the formula in Row 46 you need to change the math a little
46-33=13 46-16=30, so your formula for would need to read
"=SUM(R[-33]C-R[-16]C)/R[-16]C"

The same logic would follow for the 3rd formula which is intended to go in
row 47

--
If this helps, please remember to click yes.


"Louise" wrote:

Hi,

I have the following code in VBA to give me some variance % results.
Although the rows are always static the columns are not:

ActiveCell.FormulaR1C1 = "=SUM(R[-34]C-R[-17]C)/R[-17]C"
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "=SUM(R[-32]C-R[-15]C)/R[-15]C"
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "=SUM(R[-30]C-R[-13]C)/R[-13]C"

What I want this to do is to start in row 45, in the column i am in (worked
out prior to this in the macro) and put in a formula which basically in Excel
would read:

=SUM(I11-I28)/I28
then down one row
=SUM(I13-I30)/I30
then down one row
=SUM(I15-I32)/I32

This works, but only for the 1st and 3rd formulae, the second one is always
wrong by one row...

Am I doing something majorly wrong here?

Thanks,

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 217
Default Formula R1C1 in VBA - Strange Results (Dynamic)

Great thank you, I did have the logic right then just didn't account for the
row change where I was inputting... Appreciate your help!

"Paul C" wrote:

are you sure the 3rd formula is OK

All three of these formuls seem to be set up to reference the desired ranges
from row 45

45-34=11 45-17=28 Good for row 45 and would be SUM(I11-I28)/I28
45-32=13 45-15=30 Good for row 45 and would be SUM(I13-I30)/I3
To put the formula in Row 46 you need to change the math a little
46-33=13 46-16=30, so your formula for would need to read
"=SUM(R[-33]C-R[-16]C)/R[-16]C"

The same logic would follow for the 3rd formula which is intended to go in
row 47

--
If this helps, please remember to click yes.


"Louise" wrote:

Hi,

I have the following code in VBA to give me some variance % results.
Although the rows are always static the columns are not:

ActiveCell.FormulaR1C1 = "=SUM(R[-34]C-R[-17]C)/R[-17]C"
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "=SUM(R[-32]C-R[-15]C)/R[-15]C"
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "=SUM(R[-30]C-R[-13]C)/R[-13]C"

What I want this to do is to start in row 45, in the column i am in (worked
out prior to this in the macro) and put in a formula which basically in Excel
would read:

=SUM(I11-I28)/I28
then down one row
=SUM(I13-I30)/I30
then down one row
=SUM(I15-I32)/I32

This works, but only for the 1st and 3rd formulae, the second one is always
wrong by one row...

Am I doing something majorly wrong here?

Thanks,

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
Simple subtraction formula returning strange results = Excel glitc Ginger Excel Worksheet Functions 13 April 1st 09 07:12 PM
VLOOKUP formula results strange after copying down Code Numpty Excel Worksheet Functions 6 July 31st 08 12:18 AM
Use dynamic column reference without R1C1 Pontificateur Excel Worksheet Functions 3 February 4th 08 10:55 PM
Copy a R1C1 formula to a user defined range results #NAME? error mzehr Excel Programming 2 August 20th 07 08:50 PM
Dynamic Range in Macro with R1C1 Jonnyboy117 Excel Programming 3 July 9th 04 04:40 PM


All times are GMT +1. The time now is 04:16 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"