+ Reply to Thread
Results 1 to 4 of 4

IF Statemet returning error (#VALUE!) [Subtracting from ""]

Hybrid View

  1. #1
    Registered User
    Join Date
    06-01-2010
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    47

    Post IF Statemet returning error (#VALUE!) [Subtracting from ""]

    Hi,

    the following 'if' statement returns a #VALUE! error if the target cells have no value:

    =IF(G19-H19<0,G19-H19,"")
    Here's what I tried to fix it, which was not successful.

    =IF(G19="",IF(H19="","",IF(G19-H19>0,G19-H19,"")),IF(G19-H19>0,G19-H19,""))
    I understand that subtracting a "" value doesn't make any logical sense to excel, but is there a way to get excel to 'think' that these "" values represent 0?
    Last edited by Shane O; 02-21-2011 at 04:17 PM.

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,701

    Re: IF Statemet returning error (#VALUE!)

    Try

    =IF(COUNT(G19,H19)=2,IF(G19>H19,G19-H19,""),"")

    I'm assuming you only want to see a result if it's positive
    Audere est facere

  3. #3
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,040

    Re: IF Statemet returning error (#VALUE!)

    Mybe this:

    =IF(G19<H19,G19-H19,"")

    THis how you avoid substracting ""
    Never use Merged Cells in Excel

  4. #4
    Registered User
    Join Date
    06-01-2010
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    47

    Re: IF Statemet returning error (#VALUE!)

    Acutally I still one more question..

    There are times I need to subtract from 0 (or in this case, ""). In these rare but existant cases the error persists.

    Both solutions listed by zbor and daddylonglegs wouldn't work in this case.

    Any thoughts on how to fix this issue?


    Also, in case it helps.. I'm not manually typing these formulas in.. the folloing VBA code is being used:

    Sub FillFormula(strTarCell As String, strCell1 As String, strCell2 As String, _
            Optional bolGreater As Boolean = True, Optional shtSheet As Worksheet)
            
        Dim chrSign As String
        
        If bolGreater Then
            chrSign = ">"
        Else
            chrSign = "<"
        End If
        
        shtSheet.Range(strTarCell & "5").Value = "=IF(" & strCell1 & "5" & chrSign _
            & strCell2 & "5" & "," & strCell1 & "5-" & strCell2 & "5," _
            & Chr(34) & Chr(34) & ")"
    
    End Sub
    Last edited by Shane O; 02-21-2011 at 04:16 PM. Reason: New Issue Found

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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