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

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
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,215,338
Messages
6,124,354
Members
449,155
Latest member
ravioli44

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