I am trying to learn VBA but to be honest I am mostly relying on "record macro" to get things done.
An associate is being weened away from old Lotus spreadsheets. Evidently, text in a cell that is included in a formula is treated as a zero in Lotus, in Excel it returns #value.
Some of tis formulas are similar to this:
I have recorded a macro (bellow) that works to change his formula =a2-b2 to =n(a2)-n(b2) so he gets the results he wants:
VBA from recorded macro
Sub CellText()
'
' CellText Macro
'
'
ActiveCell.FormulaR1C1 = "=N(RC[-2])-N(RC[-1])"
'Range("D3").Select
End Sub
What I can't figure out is how to do the same thing in the event the original formula contains more than two cell references (other than record a new macro for 3, 4, 5, etc.)
For example, if the original formula is =b2-c2-d2-e2.
Any help would be most appreciated and will help me be more self-reliant in the future.
Mark
An associate is being weened away from old Lotus spreadsheets. Evidently, text in a cell that is included in a formula is treated as a zero in Lotus, in Excel it returns #value.
Some of tis formulas are similar to this:
Item | Original bid | Current Bid | Difference |
Concrete | Not included | 100 | #VALUE! |
Paving | See above | See above | #VALUE! |
Permits | 100 | 125 | -25 |
=n formula |
-100 |
0 |
-25 |
Sub CellText()
'
' CellText Macro
'
'
ActiveCell.FormulaR1C1 = "=N(RC[-2])-N(RC[-1])"
'Range("D3").Select
End Sub
What I can't figure out is how to do the same thing in the event the original formula contains more than two cell references (other than record a new macro for 3, 4, 5, etc.)
For example, if the original formula is =b2-c2-d2-e2.
Any help would be most appreciated and will help me be more self-reliant in the future.
Mark