LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sue Sue is offline
external usenet poster
 
Posts: 285
Default Use a Variable in a formula

I want to use VBA to write a formula for a cell.
I can establish where the formula needs to be put by knowing the number of
columns.
There are always 6 reference columns plus two data columns per year.
The cursor is at the start of the row.
So in the test data Numcols (an integer variable) is presently 29.
The formulae are wanted in the current row in the last two columns.
The following does put the correct formula in the correct cell.
ActiveCell.Offset(0, (NumCols + 4)).FormulaR1C1 = _
"=Round((RC[-33]*RC[-28]/100),2)"
However I always get an error when I put NumCols in the RC section €“ and I
must have NumCols because the number of columns changes but can always be
calculated.
What I want (but working!) is as below:
ActiveCell.Offset(0, (NumCols + 4)).FormulaR1C1 = _
"=Round((RC[-NumCols-4]*RC[-NumCols+1]/100),2)"
I feel this is probably a syntax issue but please can someone help?

 
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
Variable VBA Max Formula Gizmo Excel Discussion (Misc queries) 2 June 6th 08 06:12 AM
formula containing a formula-dependent variable - how? CompeterN New Users to Excel 1 November 8th 06 02:02 PM
Using a variable in a VBA formula Colin Vicary Excel Discussion (Misc queries) 3 November 8th 05 11:39 AM
Formula Variable Ronbo Excel Programming 3 March 4th 04 09:33 PM
Variable in a formula GM[_2_] Excel Programming 6 March 3rd 04 06:27 PM


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