Subtract cell formula from existing cell formula

T

transferxxx

Does anybody has a macro which would deduct the cell formula of a
selection of cells from original formula.
eg if cell A1= sum(b1:f1)
the macro would leave formula in A1 as : sum(b1:f1) - sum(b1:f1)

so that formula result of A1 would be zero
 
G

Gary''s Student

Sub whybother()
Dim r As Range
Dim s As String, s2 As String
For Each r In Selection
s = r.Formula
s2 = WorksheetFunction.Substitute(s, "=", "")
r.Formula = s & "-" & "(" & s2 & ")"
Next
End Sub
 
T

transferxxx

thxs - working great !!

Gary''s Student said:
Sub whybother()
Dim r As Range
Dim s As String, s2 As String
For Each r In Selection
s = r.Formula
s2 = WorksheetFunction.Substitute(s, "=", "")
r.Formula = s & "-" & "(" & s2 & ")"
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top