Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default R1C1 Property in VBA module

Hi all,

I am in my spreadsheet and attempting to automate it. I want to plac
a formula in (for example) cell D3 which says =C3*B3.
I have the following line of code where D3 is the Active Cell:

ActiveCell.Formula = "=RC[-1]*RC[-2]

and it works

However I then want a formula in E3 to say C3-C2.

My question is how to reference cell C2 if RC[-2] refers to C3 an
RC[-3] refers to B3.

Hope I've made myself clear

Many thanks

Seamu

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default R1C1 Property in VBA module

hi,
=rc[-2]-r[1]c[-2]
for r (row)-positive numbers are # of rows down
negative numbers are # of rows up
for c (column)-positive numbers are # of columns to right
negative numbers are # of columns to left

-----Original Message-----
Hi all,

I am in my spreadsheet and attempting to automate it. I

want to place
a formula in (for example) cell D3 which says =C3*B3.
I have the following line of code where D3 is the Active

Cell:

ActiveCell.Formula = "=RC[-1]*RC[-2]

and it works

However I then want a formula in E3 to say C3-C2.

My question is how to reference cell C2 if RC[-2] refers

to C3 and
RC[-3] refers to B3.

Hope I've made myself clear

Many thanks

Seamus


---
Message posted from http://www.ExcelForum.com/

.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 292
Default R1C1 Property in VBA module

Hi Seamus

It works like this: Numbers are absolute addresses, numbers in [ ] and no
numbers are relative

R1C2 is Row 1 column 2
RC2 is This row column 2
R[1]C2 is This row plus 1 column 2
R[-1]C2 is This row minus 1 column 2
R[-1]C[-2] is This row minus 1 this column minus 2

so
R[-1]C[-2]-RC[-2]
if I understand you right.

HTH. Best wishes Harald

"SOS " skrev i melding
...
Hi all,

I am in my spreadsheet and attempting to automate it. I want to place
a formula in (for example) cell D3 which says =C3*B3.
I have the following line of code where D3 is the Active Cell:

ActiveCell.Formula = "=RC[-1]*RC[-2]

and it works

However I then want a formula in E3 to say C3-C2.

My question is how to reference cell C2 if RC[-2] refers to C3 and
RC[-3] refers to B3.

Hope I've made myself clear

Many thanks

Seamus


---
Message posted from http://www.ExcelForum.com/



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

Excellent. Thanks to you both for such quick replies (as always on thi
forum). I have now fixed the formulae and they work just fine.

Seamu

--
Message posted from http://www.ExcelForum.com

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default R1C1 Property in VBA module

The others have given you a good explanation of R1C1 notation. To
implement, I went into E3 and put in the formula

=C3-C2

Then when to tools=Options and select the general tab, then checked R1C1
Reference file and looked at the formula. It produced:

=RC[-2]-R[-1]C[-2]

also, when assigning a formula to a cell with R1C1 notation you should do

Range("E3").FormulaR1C1 = "=RC[-2]-R[-1]C[-2]"

or you could just do

Range("E3").Formula = "=C3-C2"

While
Range("E3").Formula = "=RC[-2]-R[-1]C[-2]" does work, it is not reliable
in every case, so it is better to use FormulaR1C1.

When using Formula or FormulaR1C1 with the correct argument, it doesn't make
any difference what reference mode Excel is in.

--
Regards,
Tom Ogilvy


"SOS " wrote in message
...
Hi all,

I am in my spreadsheet and attempting to automate it. I want to place
a formula in (for example) cell D3 which says =C3*B3.
I have the following line of code where D3 is the Active Cell:

ActiveCell.Formula = "=RC[-1]*RC[-2]

and it works

However I then want a formula in E3 to say C3-C2.

My question is how to reference cell C2 if RC[-2] refers to C3 and
RC[-3] refers to B3.

Hope I've made myself clear

Many thanks

Seamus


---
Message posted 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
help on Converting R1C1 to A1 and A1 to R1C1..tia sa2 temp Excel Discussion (Misc queries) 3 September 13th 07 08:31 AM
help on Converting R1C1 to A1 and A1 to R1C1..tia sa2 temp Excel Worksheet Functions 3 September 13th 07 08:31 AM
CLASS MODULE & SIMPLE MODULE FARAZ QURESHI Excel Discussion (Misc queries) 1 September 7th 07 09:32 AM
code in module A to not execute a Worksheet_SelectionChange sub of another module Jack Sons Excel Discussion (Misc queries) 4 December 11th 05 11:52 PM
Variable from a sheet module in a class module in XL XP hglamy[_2_] Excel Programming 2 October 14th 03 05:48 PM


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