K
Kevin Sprinkel
We estimate construction projects. Frequently, we count,
say, all the piping or millwork in a particular room, and
later see that there are a number of rooms exactly like
it, so we wish to multiply a series of values. To
simplify this, I wrote the following macro:
Sub ModifyFormula()
' ModifyFormula Macro
' Macro programmed by Kevin G. Sprinkel 2/10/04
'
' Keyboard Shortcut: Ctrl-M
'
Dim cell As Range
Dim strInputString As String
strInputString = InputBox("Enter formula to modify current
formula(e). Parentheses will be added.", _
"Modify formula(e) in selected cell range
(s).")
For Each cell In Selection
If cell.HasFormula Then
If Left(cell.Formula, 1) = "=" Then
cell.Formula = Mid(cell.Formula, 2)
End If
cell.Formula = "=(" & cell.Formula & ")" &
strInputString
End If
Next
End Sub
It works fine EXCEPT if the user has simply entered a
value. In other words, it behaves as follows:
Contents of Cell Result of Macro
===================================
=432 Works
=8*2/6 Works
432 Does Not Work
I guess the latter is not interpreted as a formula. Does
anyone have a suggestion as to how to modify the macro?
Thanks.
Kevin Sprinkel
say, all the piping or millwork in a particular room, and
later see that there are a number of rooms exactly like
it, so we wish to multiply a series of values. To
simplify this, I wrote the following macro:
Sub ModifyFormula()
' ModifyFormula Macro
' Macro programmed by Kevin G. Sprinkel 2/10/04
'
' Keyboard Shortcut: Ctrl-M
'
Dim cell As Range
Dim strInputString As String
strInputString = InputBox("Enter formula to modify current
formula(e). Parentheses will be added.", _
"Modify formula(e) in selected cell range
(s).")
For Each cell In Selection
If cell.HasFormula Then
If Left(cell.Formula, 1) = "=" Then
cell.Formula = Mid(cell.Formula, 2)
End If
cell.Formula = "=(" & cell.Formula & ")" &
strInputString
End If
Next
End Sub
It works fine EXCEPT if the user has simply entered a
value. In other words, it behaves as follows:
Contents of Cell Result of Macro
===================================
=432 Works
=8*2/6 Works
432 Does Not Work
I guess the latter is not interpreted as a formula. Does
anyone have a suggestion as to how to modify the macro?
Thanks.
Kevin Sprinkel