Thread: modify formula
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default modify formula

You'd have to parse the formula into strings and numbers.

Option Explicit
Sub testme()

Dim myFormula As String
Dim LetterPart As String
Dim NumberPart As Long
Dim iCtr As Long
Dim myCell As Range

Set myCell = ActiveSheet.Range("AB151")

myFormula = myCell.Formula

For iCtr = 1 To Len(myFormula)
If IsNumeric(Mid(myFormula, iCtr, 1)) Then
'found the first number
'letterpart includes the equal sign
LetterPart = Left(myFormula, iCtr - 1)
NumberPart = Mid(myFormula, iCtr)
Exit For 'stop looking!
End If
Next iCtr

myCell.Offset(1, 0).Formula = LetterPart & NumberPart + 3
End Sub

You could parse the .FormulaR1C1 reference style formula, too. But I think that
could get confusing with adjusting the offsets (=r[xxx]c[yy] kind of thing.



FSt1 wrote:

sorry of the double post. last was a finger glitch.
if one had a formula in AB151 and the formula was =BD355, how would you add
3 to the cell reference in the formula and place formula =BC358 in range AB152

regards
FSt1


--

Dave Peterson