ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   relative cell references in vba macro (https://www.excelbanter.com/excel-programming/288443-relative-cell-references-vba-macro.html)

Sarah Bendele

relative cell references in vba macro
 
HELP! Here is what I have to work with and I do not like
having to figure out if 38 cells to the left is the
column I want to work with. I would rather use the
formula the way it is in the actual spreadsheet cell (=IF
(BJ2=0,BK2,BK2/BJ2)

instead I have this:
Sheets("Data").Select
Range("CT2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-37]=0,RC[-38],RC[-38]/RC
[-37])"

This is an extensive data tab for pivot tables with 100-
7000 rows and columns A-CZ.

Any help is appreciated.

Bob Phillips[_6_]

relative cell references in vba macro
 
Sarah,

Use Formula

Range("CT2").Formula = "=IF(BJ2=0,BK2,BK2/BJ2)"


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Sarah Bendele" wrote in message
...
HELP! Here is what I have to work with and I do not like
having to figure out if 38 cells to the left is the
column I want to work with. I would rather use the
formula the way it is in the actual spreadsheet cell (=IF
(BJ2=0,BK2,BK2/BJ2)

instead I have this:
Sheets("Data").Select
Range("CT2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-37]=0,RC[-38],RC[-38]/RC
[-37])"

This is an extensive data tab for pivot tables with 100-
7000 rows and columns A-CZ.

Any help is appreciated.




Sarah Bendele

relative cell references in vba macro
 
Thank you so much! That's so obvious, yet since I
haven't worked extensively with formulas in vba, I
wouldn't have gotten it. Works great!

Sarah
-----Original Message-----
Sarah,

Use Formula

Range("CT2").Formula = "=IF(BJ2=0,BK2,BK2/BJ2)"


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Sarah Bendele" wrote in message
...
HELP! Here is what I have to work with and I do not

like
having to figure out if 38 cells to the left is the
column I want to work with. I would rather use the
formula the way it is in the actual spreadsheet cell

(=IF
(BJ2=0,BK2,BK2/BJ2)

instead I have this:
Sheets("Data").Select
Range("CT2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-37]=0,RC[-38],RC[-

38]/RC
[-37])"

This is an extensive data tab for pivot tables with

100-
7000 rows and columns A-CZ.

Any help is appreciated.



.



All times are GMT +1. The time now is 07:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com