Estimator#1
New Member
- Joined
- Apr 4, 2011
- Messages
- 5
I have a repetitive need to modify a formula the same way on a consistent basis.
If I had a true a keystroke type macro, it would be very easy to program... but VBA does not seem to work that way.
The specific example allows me to modify a cells contents based on the mere existence of data in another cell. I end up doing this a lot after the original formula is written.
I am trying to change from (With ActiveCell=k8)
=H8*G8/I8
to
=IF(E8<>"",H8*G8/I8,"").
After some scrounging around i have come up with this...and assign it to a hot key.
Sub ifzero()
'
' ifzero Macro
main = ActiveCell.Formula
pre = "=IF(RC[-6]<>"""","
Post = ","""")"
ActiveCell.FormulaR1C1 = pre & Mid(main, 2, 100) & Post
End Sub
I used the Mid statement to get rid of the "=" that is at the beginning of the line. (Without that I get an error)
This does not work. It puts the cell addresses in the formula in single quiotes... ie
=IF(I8<>"",'H8'*'G8'/'I8',"")
Is there a way to tell excel to open the editor, move to the beginning, add something and close the editor, or is this type of VBA the best way to do this.
I have thought about find replace, but for me, editing the cell directly is not any slower, esp when only dealing with one or two cells at a time.
If I had a true a keystroke type macro, it would be very easy to program... but VBA does not seem to work that way.
The specific example allows me to modify a cells contents based on the mere existence of data in another cell. I end up doing this a lot after the original formula is written.
I am trying to change from (With ActiveCell=k8)
=H8*G8/I8
to
=IF(E8<>"",H8*G8/I8,"").
After some scrounging around i have come up with this...and assign it to a hot key.
Sub ifzero()
'
' ifzero Macro
main = ActiveCell.Formula
pre = "=IF(RC[-6]<>"""","
Post = ","""")"
ActiveCell.FormulaR1C1 = pre & Mid(main, 2, 100) & Post
End Sub
I used the Mid statement to get rid of the "=" that is at the beginning of the line. (Without that I get an error)
This does not work. It puts the cell addresses in the formula in single quiotes... ie
=IF(I8<>"",'H8'*'G8'/'I8',"")
Is there a way to tell excel to open the editor, move to the beginning, add something and close the editor, or is this type of VBA the best way to do this.
I have thought about find replace, but for me, editing the cell directly is not any slower, esp when only dealing with one or two cells at a time.