+ Reply to Thread
Results 1 to 2 of 2

MAKE CELL BLANK IF VALUE = 0 (any ideas on adding an if stament to VBA code)

  1. #1
    Registered User
    Join Date
    03-26-2013
    Location
    Ireland
    MS-Off Ver
    Excel 2003
    Posts
    2

    Question MAKE CELL BLANK IF VALUE = 0 (any ideas on adding an if stament to VBA code)

    I am trying to make cells in a row subtract the two cells in the above to rows from each other (A1 - A2 = A3 )

    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 on the spreadsheet 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)

    Thanks

    Erol

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: MAKE CELL BLANK IF VALUE = 0 (any ideas on adding an if stament to VBA code)

    I don't really understand your explanation and the code example of the range that requires formula.
    but you need to use an IF condition in the formula.

    Please Login or Register  to view this content.
    which will give you a formula in A3 of =IF(A1-A2=0,"",A1-A2)
    Cheers
    Andy
    www.andypope.info

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1