View Full Version : [SOLVED:] "IF" statement isn't reading binaries properly
huntrashmi
09-12-2024, 09:13 PM
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?
Aflatoon
09-13-2024, 03:51 AM
There is no way that code is doing that. It will only assign Pass if the value is 1 when it runs.
Aussiebear
09-13-2024, 08:58 PM
What happens if you enter this formula in cell K37?
=If(L70 = 1,"Pass",If(And(B70 =1,L70 = 0),"Fail","DNP"))
jdelano
09-15-2024, 03:45 AM
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 ...
huntrashmi
09-15-2024, 07:27 PM
There is no way that code is doing that. It will only assign Pass if the value is 1 when it runs.
Thank you!
huntrashmi
09-15-2024, 07:28 PM
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
Aussiebear
09-15-2024, 10:43 PM
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.
Paul_Hossler
09-16-2024, 05:52 AM
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
Aussiebear
09-17-2024, 02:18 PM
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.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.