+ Reply to Thread
Results 1 to 3 of 3

Testing two conditions, one over rides the other?

Hybrid View

  1. #1
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,192

    Testing two conditions, one over rides the other?

    The following code is attempting to check the conditon of the value of a cell.
    If the value is less than ".108" I want to show the difference.
    If the value is greater than ".110" I want to show the difference.

    I think my problem right now is, if condition one is met condition two over rides condition one. (or vice~versa).

    How can I make this work?

    Sub check_L()
    Selection.NumberFormat = "0.0000" 'Set decimal places
    Range("L9").Select
    If Range("C9") <= "0.108000" Then
    Range("L9").Value = Range("C9").Value - "0.108000" '(Difference of)
    End If
        Range("L9").Select
    If Range("C9") >= "0.110000" Then
    Range("L9").Value = Range("C9").Value - "0.110000" '(Difference of)
    End If
        If Range("L9").Value = "0" Then 'If value = .0000 then make blank
        Range("L9").Value = ""
        End If
    End Sub
    Regards

    Rick
    Win10, Office 365

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    I think this might work for you. I eliminated some of the unneeded selecting of Range("L9"), but left one. It's not needed for the code here, but I thought you might have another purpose for it.
    Sub check_L()
    Selection.NumberFormat = "0.0000" 'Set decimal places
    Range("L9").Select
    If Range("C9") <= "0.108000" Then
       Range("L9").Value = Range("C9").Value - "0.108000" '(Difference of)
    Else
       If Range("C9") >= "0.110000" Then _
            Range("L9").Value = Range("C9").Value - "0.110000" '(Difference of)
       If Range("L9").Value = "0" Then 'If value = .0000 then Range("L9").Value = ""   
    End If
    End Sub

  3. #3
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,192
    You know, I used nearly (I had the long version) the same code as you including missing the second "end if" at the end of the code, butt, and I use that word literally, what I did not see was the typo I made with the numeric value I wanted to use!

    I typed ".108" instead of ".109"!
    Since my less than 5th grade math is less than par, and I beat them damn kids on that show already, I may need to go back to skool!

    So, a value of say; ".1089" would not be less than ".108" hence a blank cell. At this point I know I'm on track as I just asked my kid. :lol:

    Thanks for your help! (Seriously)

+ 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