Make Cell blank if value is zero! Adding IF Statements to Code

eaykan

New Member
Joined
Mar 20, 2013
Messages
15
I am trying to make cells in a row subtract the two cells in the above to rows from each other (A1 - A2 = A3 ) using the below diagram.

THE code is as follows:

Sub Module2()
Range("A3:B3" & lastrow).Formula = "=A1-A2"
End Sub


However I am trying to make the cell appear blank if the value = zero (i know this can be done using conditional formatting but i can’t use this method as it is disrupts the heat map i have created as i have defined a formatting range to the end of the last column in the row and do not want the zeros to disrupt the formatting)


My problem is that i am can’t seem to get the right code in place for the macro so that it automatically subtracts the rows (A1&A2) but leaves the cell blank if it is zero (as i do not want it to affect my conditional formatting IF I extend the formula to the end of the sheet waiting for the fields to be populated above it (the formula) on a monthly basis)
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Solved! Code is below:

Sub Module2()
Range("D15:XFD15" & lastrow).Formula = "=D13-D14"
For Each cell In Range("D15:XFD15")
If cell.Value = "0" Then cell.Clear
Next
End Sub
 
Upvote 0
Any ideas on a way to remove all the conditional formating in cells that have a zero value in them?
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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