Consulting

Results 1 to 9 of 9

Thread: "IF" statement isn't reading binaries properly

  1. #1

    "IF" statement isn't reading binaries properly

    Hello, I'm writing an "IF" statement that checks two binaries for me. It is written as such:
    If Range("L70").Value = 1 Then
    Range("K37") = "Pass"
    ElseIf Range("B70").Value = 1 And Range("L70").Value = 0 Then
    Range("K37") = "Fail"
    Else: Range("K37") = "DNP"
    End If
    However, despite L70's value being 0, it still changes K37 to "Pass." What am I writing wrong in this statement?
    Last edited by Aussiebear; 09-15-2024 at 10:31 PM.

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,783
    Location
    There is no way that code is doing that. It will only assign Pass if the value is 1 when it runs.
    Be as you wish to seem

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,259
    Location
    What happens if you enter this formula in cell K37?
    =If(L70 = 1,"Pass",If(And(B70 =1,L70 = 0),"Fail","DNP"))
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  4. #4
    It would be very helpful if you uploaded the workbook, seeing the actual data the If statement is checking is necessary in understanding why you're not receiving the results you're expecting.

    edit: If to It ...

  5. #5
    Quote Originally Posted by Aflatoon View Post
    There is no way that code is doing that. It will only assign Pass if the value is 1 when it runs.
    Thank you!

  6. #6
    Quote Originally Posted by Aussiebear View Post
    What happens if you enter this formula in cell K37?
    =If(L70 = 1,"Pass",If(And(B70 =1,L70 = 0),"Fail","DNP"))
    Sorry, my mistake, I meant despite L70 being 0, it still makes K37 "Pass." Thanks for catching that

  7. #7
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,259
    Location
    Hmmm.. my testing shows that;
    if L70 =1, the formula gives you a "Pass".

    If L70 <> 1 then it passes through to the next testing, to see if B70 =1 and L70 =0, and if so, it gives you a "Fail".

    If neither L70 or B70 are = to 1 then it gives you a "DNP".

    which is what I thought you wanted.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  8. #8
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,796
    Location
    I'm confused

    Do you want a VBA or a worksheet formula solution

    The attachment has both and seems to do what you asked for
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  9. #9
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,259
    Location
    It seems that this topic was posted elsewhere and the OP has since posted this:
    SOLVED: My apologies everyone, learned a lot about VBA from you all, but it was a stupid mistake on my end. The IF statement that determined L70's value of 1 or 0 was dependent on cells that were also getting updated during this Sub. Thought excel was finishing the whole Sub, and then updating the cells, when it was actually re-evaluating each cell after each action it performed. Thanks everyone who helped out; a lot of your Debugging best-practices led to me figuring that out.
    So for all of you who tried to assist here, thank you on behalf of huntrashmi.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

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