Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default VBA Excel formula error

Hi,
I'm trying to use a variable in a formula and it's not working. Here is the
formula:

Formula #1
ActiveCell.FormulaR1C1 = "=rc[x]-rc[2]"

The value of x is determined in a select case statement. For example
depending on the case selection I want the formula to say:

Formula #2
ActiveCell.FormulaR1C1 = "rc[-17]-rc[2]"

Formula #2 works but Formula #1 doesn't. How can I use a variable in #1 and
make it work?

Thanks much,
--
TomD
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default VBA Excel formula error

if x is inside the quotes it is treated as text, not as your variable - do
this instead:
ActiveCell.FormulaR1C1 = "=rc[" & x & "]-rc[2]"

"TomD" wrote:

Hi,
I'm trying to use a variable in a formula and it's not working. Here is the
formula:

Formula #1
ActiveCell.FormulaR1C1 = "=rc[x]-rc[2]"

The value of x is determined in a select case statement. For example
depending on the case selection I want the formula to say:

Formula #2
ActiveCell.FormulaR1C1 = "rc[-17]-rc[2]"

Formula #2 works but Formula #1 doesn't. How can I use a variable in #1 and
make it work?

Thanks much,
--
TomD

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
Error with sum formula in excel 2007 Heera Excel Worksheet Functions 4 October 9th 08 06:20 PM
#NAME? error in formula in 03 but runs okay in excel 07 mrpye Excel Discussion (Misc queries) 4 August 27th 08 07:12 PM
Excel Formula Error Griffey5 Excel Worksheet Functions 15 January 7th 08 10:00 AM
Why does Excel say this formula contains an error? HuskerBronco Excel Worksheet Functions 12 July 15th 06 10:26 PM
Excel Formula Error VikiFynn Excel Worksheet Functions 1 October 27th 05 03:48 PM


All times are GMT +1. The time now is 08:51 AM.

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"