Edit a formula in multiple cells

migueltr14

New Member
Joined
Feb 12, 2019
Messages
2
Hi!,

I want to have a macro that would allow me to change the formula (A1-B1) to +if(abs(A1-B1)<0.000000001,0,A1-B1) to multiple cells in a range.

Thanks!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi, you could try this on a copy of your workbook.

Select the cells you want to change and run the macro.

Note: this will change every formula in the selected range.

Code:
Sub m()
Dim c As Range
For Each c In Selection
    If c.HasFormula Then c.Formula = "=IF(" & Mid(c.Formula, 2) & "<0.000000001,0," & Mid(c.Formula, 2) & ")"
Next c
End Sub
 
Upvote 0
Thanks, FormR! it worked!, I just added the abs function and it's amazing. Thanks again!

Rich (BB code):
Rich (BB code):
Sub m()
Dim c As Range
For Each c In Selection
    If c.HasFormula Then c.Formula = "=IF(abs(" & Mid(c.Formula, 2) & ")<0.000000001,0," & Mid(c.Formula, 2) & ")"
Next c
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top