Macro to quickly add if statement to already filled cells

d2theustin

New Member
Joined
Jun 10, 2018
Messages
1
Hello there,

I have a spreadsheet with already filled data/formulas. I want to add an if statement to ensure if the reference cell is blank it shows the cell blank until a value is filled.. like: =IF(ISBLANK(E24),"",F24/G24).. I know how to do that.

However, I don't want to go through every single cell and do this as there are a lot of data points/calculations. so is there a way to create a macro to do this for me.. Here's my sheet:
https://drive.google.com/open?id=1wdg-gLFHuO54uA3DklhSoRrYSSkTWlRE

So basically, I want to add =IF(ISBLANK(E4),"",ALREADY ENTERED FORMULA) to all the cells in Cols I-N. and have the macro understand to change E4 to E5 and so on as it goes down the sheet.

Just trying to save some time to not go through and re-type all the formulas.

Hope this makes sense..

D
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Give this macro a try...
Code:
[table="width: 500"]
[tr]
	[td]Sub AddTestForBlanksToFormulas()
  Dim LastRow As Long, Cell As Range
  LastRow = Columns("I:N").Find("*", , xlFormulas, , xlRows, xlPrevious, , , False).Row
  For Each Cell In Range("I2:N" & LastRow)
    If Cell.HasFormula Then Cell.Formula = "=IF(ISBLANK(E" & Cell.Row & "),""""," & Mid(Cell.Formula, 2) & ")"
  Next
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,215,446
Messages
6,124,896
Members
449,194
Latest member
JayEggleton

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