Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro Assistance with Incrementing Formula


I have an Excel sheet that I use to keep track of salespeople's dail
statistics, which has manual changes made to it daily. These change
are made to the formula resident within the cell by either incrementin
or decrementing the last number in the formula.
The below code is from merely recording a new macro, selecting the to
data cell in the column, and then clicking within the fx textbox
revealing the formula...

Code
-------------------

Sub UpdateDaily()
'
' UpdateDaily Macro
'
Range("V2").Select
ActiveCell.FormulaR1C1 = "=(165-RC[-20])/48"

End Sub

-------------------


What I want is for the formula: =(165-B2)/48 to be decreased by 1 eac
time the macro is run, so that it will now be...=(165-B2)/47, and the
=(165-B2)/46...each time I run the macro.

If anyone can help me with this, it will be deeply appreciated.

Thank yo

--
Relyk
-----------------------------------------------------------------------
Relykk's Profile: http://www.excelforum.com/member.php...fo&userid=1575
View this thread: http://www.excelforum.com/showthread.php?threadid=27267

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Macro Assistance with Incrementing Formula

How about:

Option Explicit
Sub UpdateDaily2()

Dim myFormula As String
Dim myValue As String
Dim iCtr As Long

With Worksheets("sheet1")
myFormula = .Range("V2").FormulaR1C1
For iCtr = Len(myFormula) To 1 Step -1
If Mid(myFormula, iCtr, 1) = "/" Then
'found the /
myValue = Mid(myFormula, iCtr + 1)
If IsNumeric(myValue) Then
If myValue < 1 Then
myFormula = Mid(myFormula, 1, iCtr) & CDbl(myValue) - 1
.Range("v2").FormulaR1C1 = myFormula
Exit For
Else
MsgBox "division by 0???"
End If
End If
End If
Next iCtr
End With

End Sub


Relykk wrote:

I have an Excel sheet that I use to keep track of salespeople's daily
statistics, which has manual changes made to it daily. These changes
are made to the formula resident within the cell by either incrementing
or decrementing the last number in the formula.
The below code is from merely recording a new macro, selecting the top
data cell in the column, and then clicking within the fx textbox,
revealing the formula...

Code:
--------------------

Sub UpdateDaily()
'
' UpdateDaily Macro
'
Range("V2").Select
ActiveCell.FormulaR1C1 = "=(165-RC[-20])/48"

End Sub

--------------------

What I want is for the formula: =(165-B2)/48 to be decreased by 1 each
time the macro is run, so that it will now be...=(165-B2)/47, and then
=(165-B2)/46...each time I run the macro.

If anyone can help me with this, it will be deeply appreciated.

Thank you

--
Relykk
------------------------------------------------------------------------
Relykk's Profile: http://www.excelforum.com/member.php...o&userid=15758
View this thread: http://www.excelforum.com/showthread...hreadid=272679


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro Assistance with Incrementing Formula


Relykk


TRY


Sub UpdateDaily()
'
' UpdateDaily Macro
'
Dim i As Integer
Dim s As String

s$ = Range("v2").FormulaR1C1
i = InStr(1, Range("v2").FormulaR1C1, "/")
s$ = Left(s, i) & Mid(s, i + 1) - 1
Range("v2").FormulaR1C1 = s
End Sub


--
mudraker
------------------------------------------------------------------------
mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473
View this thread: http://www.excelforum.com/showthread...hreadid=272679

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Macro Assistance with Incrementing Formula

If your formula is entered in cell Z10, the following code will decrease the
final number by one every time it is run.
Sub Test()
strFormula = Cells(10, 26).FormulaR1C1
intSlash = InStr(1, strFormula, "/")
If InStr(1, strFormula, "/") 0 Then
LastNumber = Mid(strFormula, intSlash + 1, Len(strFormula) -
intSlash)
strFormula = Left(strFormula, Len(strFormula) - Len(LastNumber)) _
& Trim(Str(Val(LastNumber) - 1))
Cells(10, 26).FormulaR1C1 = strFormula
End If
End Sub

HTH
Chris

"Relykk" wrote in message
...

I have an Excel sheet that I use to keep track of salespeople's daily
statistics, which has manual changes made to it daily. These changes
are made to the formula resident within the cell by either incrementing
or decrementing the last number in the formula.
The below code is from merely recording a new macro, selecting the top
data cell in the column, and then clicking within the fx textbox,
revealing the formula...

Code:
--------------------

Sub UpdateDaily()
'
' UpdateDaily Macro
'
Range("V2").Select
ActiveCell.FormulaR1C1 = "=(165-RC[-20])/48"

End Sub

--------------------


What I want is for the formula: =(165-B2)/48 to be decreased by 1 each
time the macro is run, so that it will now be...=(165-B2)/47, and then
=(165-B2)/46...each time I run the macro.

If anyone can help me with this, it will be deeply appreciated.

Thank you


--
Relykk
------------------------------------------------------------------------
Relykk's Profile:

http://www.excelforum.com/member.php...o&userid=15758
View this thread: http://www.excelforum.com/showthread...hreadid=272679



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
Incrementing Formula by Column Instead of by Row Andy Excel Worksheet Functions 1 February 12th 10 03:04 PM
MACRO assistance MrDave Excel Discussion (Misc queries) 1 August 12th 09 01:10 PM
Macro assistance Rover Excel Worksheet Functions 11 March 17th 09 04:30 PM
Incrementing a formula by X number Bowbender Excel Worksheet Functions 3 September 21st 05 04:14 PM
Incrementing formula by two rows Ben Hur Excel Worksheet Functions 1 February 24th 05 09:21 PM


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