VBA to change current formula

rahmaddanis

New Member
Joined
Apr 1, 2015
Messages
6
Dear all,
I have many cells with formula in it. I want to update the formula of the selected cells by adding if statement to the current formula to replace 0 result with "" (empty string).

Here what I want to achieve
=IF("current formula result"=0,"","current formula")

e.g
below formula return 0 because no data
=SUMIFS(TGR!$Z8:$Z62,TGR!$C8:$C62,$B$9,TGR!$X8:$X62,1)

I want to modify it so 0 value change to "", the formula should becomes
=IF(SUMIFS(TGR!$Z8:$Z62,TGR!$C8:$C62,$B$9,TGR!$X8:$X62,1)=0,"",=SUMIFS(TGR!$Z8:$Z62,TGR!$C8:$C62,$B$9,TGR!$X8:$X62,1))

How to do it easily in the shortest time?. appreciate your help.
thanks.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hi,

Try this

Code:
Sub somesub()
Dim r, c As Range
For Each c In Selection
If c.HasFormula Then
r = Mid(c.Formula, 2)
c.Formula = "=IF(" & r & "=0,""""," & r & " )"
End If
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,195
Members
449,072
Latest member
DW Draft

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