Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default Assign value depending on position in formula

I use the following code to change my formula from:
=SUM(OFFSET(C50,-6,78,-12,1))/SUM(OFFSET(C50,-6,-1,-12,1))
to
=SUM(OFFSET(C50,-7,80,-12,1))/SUM(OFFSET(C50,-7,-3,-12,1))
Sub AdjustNew12Formulas()
U = 6
R = 78
L = 1
For x = 1 To 28
ActiveCell.FormulaR1C1 = _
"=SUM(OFFSET(RC,-" & U & "," & R & ",-12,1))/SUM(OFFSET(RC,-" & U &
",-" & L & ",-12,1))"
ActiveCell.Offset(0, 2).Range("A1").Select

U = U + 1
R = R - 1
L = L + 2
Next x

What I need at this point is a way to determine what my variables are to
begin with. In other words, if the first part of the formula is
SUM(OFFSET(C50,-6,78,-12,1)) I want it to set the starting point for U at 6,
starting point for R as 78, etc...

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default Assign value depending on position in formula

Assuming that the formula is already in the activecell...
U = mid(activecell.formula,instr(1,activecell.Formula, ",-")+2,1)

That should get you going. Let me know if you need exact code.

HTH

Die_Another_Day
StephanieH wrote:
I use the following code to change my formula from:
=SUM(OFFSET(C50,-6,78,-12,1))/SUM(OFFSET(C50,-6,-1,-12,1))
to
=SUM(OFFSET(C50,-7,80,-12,1))/SUM(OFFSET(C50,-7,-3,-12,1))
Sub AdjustNew12Formulas()
U = 6
R = 78
L = 1
For x = 1 To 28
ActiveCell.FormulaR1C1 = _
"=SUM(OFFSET(RC,-" & U & "," & R & ",-12,1))/SUM(OFFSET(RC,-" & U &
",-" & L & ",-12,1))"
ActiveCell.Offset(0, 2).Range("A1").Select

U = U + 1
R = R - 1
L = L + 2
Next x

What I need at this point is a way to determine what my variables are to
begin with. In other words, if the first part of the formula is
SUM(OFFSET(C50,-6,78,-12,1)) I want it to set the starting point for U at 6,
starting point for R as 78, etc...


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default Assign value depending on position in formula

Yay. That worked.

Thanks for your help!

Here's the finished product for anyone interested:

Sub AdjustNew12Formulas()
U = Mid(ActiveCell.Formula, InStr(1, ActiveCell.Formula, ",-") + 2, 1)
R = Mid(ActiveCell.Formula, InStr(1, ActiveCell.Formula, ",-") + 4, 2)
L = Mid(ActiveCell.Formula, InStr(1, ActiveCell.Formula, ",-") + 34, 1)
For x = 1 To 28
ActiveCell.FormulaR1C1 = _
"=SUM(OFFSET(RC,-" & U & "," & R & ",-12,1))/SUM(OFFSET(RC,-" & U &
",-" & L & ",-12,1))"
ActiveCell.Offset(0, 2).Range("A1").Select

U = U + 1
R = R - 1
L = L + 2
Next x

End Sub


"Die_Another_Day" wrote:

Assuming that the formula is already in the activecell...
U = mid(activecell.formula,instr(1,activecell.Formula, ",-")+2,1)

That should get you going. Let me know if you need exact code.

HTH

Die_Another_Day
StephanieH wrote:
I use the following code to change my formula from:
=SUM(OFFSET(C50,-6,78,-12,1))/SUM(OFFSET(C50,-6,-1,-12,1))
to
=SUM(OFFSET(C50,-7,80,-12,1))/SUM(OFFSET(C50,-7,-3,-12,1))
Sub AdjustNew12Formulas()
U = 6
R = 78
L = 1
For x = 1 To 28
ActiveCell.FormulaR1C1 = _
"=SUM(OFFSET(RC,-" & U & "," & R & ",-12,1))/SUM(OFFSET(RC,-" & U &
",-" & L & ",-12,1))"
ActiveCell.Offset(0, 2).Range("A1").Select

U = U + 1
R = R - 1
L = L + 2
Next x

What I need at this point is a way to determine what my variables are to
begin with. In other words, if the first part of the formula is
SUM(OFFSET(C50,-6,78,-12,1)) I want it to set the starting point for U at 6,
starting point for R as 78, etc...



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
Formula to add depending upon value entered lheck77 Excel Worksheet Functions 4 September 10th 09 04:12 PM
Same formula, different results depending on machine? Ken Johnson Excel Worksheet Functions 9 August 12th 07 12:07 PM
Formula Depending On Formatting SamuelT Excel Discussion (Misc queries) 1 July 3rd 06 05:44 PM
Formula to look for value in a row depending on unknown value? pcsski Excel Worksheet Functions 2 April 25th 06 08:25 PM
Value or formula in cell depending on input... Jan Jansens[_2_] Excel Programming 4 September 6th 05 08:54 PM


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