urgent - nested ifs

jubilee101

New Member
Joined
Apr 17, 2013
Messages
25
Hi guys,
i'm under pressure to get this done in next 3 hours ao any help would be appreciated.

lets say I have 4 cells ABCD. The text in A can will either say "Pass" or "Fail" depending on the following:

IF (B,C,D = blank ) then A=“Pass”
If B not blank but C,D are Blank, then A=“Fail”
If B is not blank and C is not blank then A=“Pass”
IF( B,C,D not blank, then A=“fail”)

I've tried doing nest IFs & AND and I just can't get it to work:eek:
 
Last edited:

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Is it enough to just check for the two "Pass" conditions, and assume all other "False" (if not, then that most mean that there are other situations not accounted for, and what should happen in those situations)?
If so, you can simply use:
Code:
=IF(OR(AND(B1="",C1="",D1=""),AND(B1<>"",C1<>"")),"Pass","Fail")
 
Upvote 0
Hi guys,
i'm under pressure to get this done in next 3 hours ao any help would be appreciated.

lets say I have 4 cells ABCD. The text in A can will either say "Pass" or "Fail" depending on the following:

IF (B,C,D = blank ) then A=“Pass”
If B not blank but C,D are Blank, then A=“Fail”
If B is not blank and C is not blank then A=“Pass”
IF( B,C,D not blank, then A=“fail”)

I've tried doing nest IFs & AND and I just can't get it to work:eek:

This VBA solution should work assuming the columns you are working with are A,B,C and D

Code:
Sub Pass_or_Fail()


Dim Hold As Variant, X As Long, RR As Range
    
    With ActiveSheet.UsedRange
     
        Set RR = .Columns(1)
    
        For X = 2 To 4
            Set RR = Application.Union(RR, .Columns(X))
        Next X
    
    End With
    
    Hold = RR.Value2
    
    For X = 1 To UBound(Hold, 1)

                'B                        'C               'D

        If Hold(X, 2) = "" And Hold(X, 3) = "" And Hold(X, 4) = "" Then
        
            Hold(X, 1) = "Pass"'A
        
        ElseIf Hold(X, 2) <> "" And Hold(X, 3) = "" And Hold(X, 4) = "" Then
        
            Hold(X, 1) = "Pass" = "Fail"
    
        ElseIf Hold(X, 2) <> "" And Hold(X, 3) <> "" Then
        
            Hold(X, 1) = "Pass"
        
        ElseIf Hold(X, 2) <> "" And Hold(X, 3) <> "" And Hold(X, 4) <> "" Then
        
            Hold(X, 1) = "Fail"
            
        End If
    
    Next X


    RR.Columns(1).Value2 = WorksheetFunction.Index(Hold, 0, 1)'update column A


End Sub
 
Last edited:
Upvote 0
Try this...

Code:
if Range("B1:D1").value=empty then Range("A1").value="Pass"
elseif not Range("B1").Value=empty and Range("C1:D1").value=empty then Range("A1").value = "Fail"
elseif not Range("B1,C1").value=empty then Range("A1").value = "Pass"
elseif not Range("B1:D1").value=empty then Range("A1").value = "Fail"
else
end if
 
Upvote 0
You can use VBA if you want to, but it isn't really necessary here.
 
Upvote 0
@joe4

Is it enough to just check for the two "Pass" conditions, and assume all other "False" (if not, then that most mean that there are other situations not accounted for, and what should happen in those situations)?
If so, you can simply use:
Code:
=IF(OR(AND(B1="",C1="",D1=""),AND(B1<>"",C1<>"")),"Pass","Fail")

This works for the cells when B,C,D blank. however it isn't changing A to "Fail" if b,c, d are not blank?
 
Last edited:
Upvote 0
This works for the cells when B,C,D blank. however it isn't changing A to "Fail" if b,c, d are not blank?
That seems to contradict one of your original conditions:
If B is not blank and C is not blank then A=“Pass”

Listed below is all possibilities. Please fill in the missing result for each one:
Code:
[TABLE="width: 256"]
<tbody>[TR]
[TD="class: xl64, width: 64"]A Blank[/TD]
[TD="class: xl64, width: 64"]B Blank[/TD]
[TD="class: xl64, width: 64"]C Blank[/TD]
[TD="class: xl64, width: 64"]Result[/TD]
[/TR]
[TR]
[TD="align: center"]TRUE[/TD]
[TD="align: center"]TRUE[/TD]
[TD="align: center"]TRUE[/TD]
[TD="class: xl63"]Pass[/TD]
[/TR]
[TR]
[TD="align: center"]TRUE[/TD]
[TD="align: center"]TRUE[/TD]
[TD="align: center"]FALSE[/TD]
[TD="class: xl63"][/TD]
[/TR]
[TR]
[TD="align: center"]TRUE[/TD]
[TD="align: center"]FALSE[/TD]
[TD="align: center"]FALSE[/TD]
[TD="class: xl63"][/TD]
[/TR]
[TR]
[TD="align: center"]TRUE[/TD]
[TD="align: center"]FALSE[/TD]
[TD="align: center"]TRUE[/TD]
[TD="class: xl63"][/TD]
[/TR]
[TR]
[TD="align: center"]FALSE[/TD]
[TD="align: center"]FALSE[/TD]
[TD="align: center"]FALSE[/TD]
[TD="class: xl63"]Fail[/TD]
[/TR]
[TR]
[TD="align: center"]FALSE[/TD]
[TD="align: center"]FALSE[/TD]
[TD="align: center"]TRUE[/TD]
[TD="class: xl63"][/TD]
[/TR]
[TR]
[TD="align: center"]FALSE[/TD]
[TD="align: center"]TRUE[/TD]
[TD="align: center"]FALSE[/TD]
[TD="class: xl63"][/TD]
[/TR]
[TR]
[TD="align: center"]FALSE[/TD]
[TD="align: center"]TRUE[/TD]
[TD="align: center"]TRUE[/TD]
[TD="class: xl63"]Fail[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Joe,
the cells are populated in order from left to right depending on where we are in the process, so for example, we'd never have the 2nd or 3rd line occur where Cell D has an entry but b & C don't:

Code:
[TABLE="width: 256"]
 <colgroup><col width="64" span="4" style="width:48pt"> </colgroup><tbody>[TR]
  [TD="class: xl63, width: 64"]A Blank[/TD]
  [TD="class: xl63, width: 64"]B Blank[/TD]
  [TD="class: xl63, width: 64"]C Blank[/TD]
  [TD="class: xl63, width: 64"]Result[/TD]
 [/TR]
 [TR]
  [TD="class: xl64, width: 64"]TRUE[/TD]
  [TD="class: xl64, width: 64"]TRUE[/TD]
  [TD="class: xl64, width: 64"]TRUE[/TD]
  [TD="class: xl63, width: 64"]Pass[/TD]
 [/TR]
 [TR]
  [TD="class: xl64, width: 64"]TRUE[/TD]
  [TD="class: xl64, width: 64"]TRUE[/TD]
  [TD="class: xl64, width: 64"]FALSE[/TD]
  [TD="class: xl63, width: 64"]Pass[/TD]
 [/TR]
 [TR]
  [TD="class: xl64, width: 64"]TRUE[/TD]
  [TD="class: xl64, width: 64"]FALSE[/TD]
  [TD="class: xl64, width: 64"]FALSE[/TD]
  [TD="class: xl63, width: 64"]Pass[/TD]
 [/TR]
 [TR]
  [TD="class: xl64, width: 64"]TRUE[/TD]
  [TD="class: xl64, width: 64"]FALSE[/TD]
  [TD="class: xl64, width: 64"]TRUE[/TD]
  [TD="class: xl63, width: 64"]Pass[/TD]
 [/TR]
 [TR]
  [TD="class: xl64, width: 64"]FALSE[/TD]
  [TD="class: xl64, width: 64"]FALSE[/TD]
  [TD="class: xl64, width: 64"]FALSE[/TD]
  [TD="class: xl63, width: 64"]Fail[/TD]
 [/TR]
 [TR]
  [TD="class: xl64, width: 64"]FALSE[/TD]
  [TD="class: xl64, width: 64"]FALSE[/TD]
  [TD="class: xl64, width: 64"]TRUE[/TD]
  [TD="class: xl63, width: 64"]Pass[/TD]
 [/TR]
 [TR]
  [TD="class: xl64, width: 64"]FALSE[/TD]
  [TD="class: xl64, width: 64"]TRUE[/TD]
  [TD="class: xl64, width: 64"]FALSE[/TD]
  [TD="class: xl63, width: 64"]Fail[/TD]
 [/TR]
 [TR]
  [TD="class: xl64, width: 64"]FALSE[/TD]
  [TD="class: xl64, width: 64"]TRUE[/TD]
  [TD="class: xl64, width: 64"]TRUE[/TD]
  [TD="class: xl63, width: 64"]Fail
[/TD]
[/TR]
</tbody>[/TABLE]

That seems to contradict one of your original conditions:


Listed below is all possibilities. Please fill in the missing result for each one:
Code:
[TABLE="width: 256"]
<tbody>[TR]
[TD="class: xl64, width: 64"]A Blank[/TD]
[TD="class: xl64, width: 64"]B Blank[/TD]
[TD="class: xl64, width: 64"]C Blank[/TD]
[TD="class: xl64, width: 64"]Result[/TD]
[/TR]
[TR]
[TD="align: center"]TRUE[/TD]
[TD="align: center"]TRUE[/TD]
[TD="align: center"]TRUE[/TD]
[TD="class: xl63"]Pass[/TD]
[/TR]
[TR]
[TD="align: center"]TRUE[/TD]
[TD="align: center"]TRUE[/TD]
[TD="align: center"]FALSE[/TD]
[TD="class: xl63"][/TD]
[/TR]
[TR]
[TD="align: center"]TRUE[/TD]
[TD="align: center"]FALSE[/TD]
[TD="align: center"]FALSE[/TD]
[TD="class: xl63"][/TD]
[/TR]
[TR]
[TD="align: center"]TRUE[/TD]
[TD="align: center"]FALSE[/TD]
[TD="align: center"]TRUE[/TD]
[TD="class: xl63"][/TD]
[/TR]
[TR]
[TD="align: center"]FALSE[/TD]
[TD="align: center"]FALSE[/TD]
[TD="align: center"]FALSE[/TD]
[TD="class: xl63"]Fail[/TD]
[/TR]
[TR]
[TD="align: center"]FALSE[/TD]
[TD="align: center"]FALSE[/TD]
[TD="align: center"]TRUE[/TD]
[TD="class: xl63"][/TD]
[/TR]
[TR]
[TD="align: center"]FALSE[/TD]
[TD="align: center"]TRUE[/TD]
[TD="align: center"]FALSE[/TD]
[TD="class: xl63"][/TD]
[/TR]
[TR]
[TD="align: center"]FALSE[/TD]
[TD="align: center"]TRUE[/TD]
[TD="align: center"]TRUE[/TD]
[TD="class: xl63"]Fail[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
I was off a column in my grid, it is not A, B, C, but rather B, C, D. But I can now see what you are after.
Since there are only two conditions that would return "Fail", let's check for those, and then have anything else return "Pass", i.e.
Code:
=IF(OR(AND(B1<>"",C1<>"",D1<>""),AND(B1<>"",D1<>"")),"Fail","Pass")
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,251
Members
448,556
Latest member
peterhess2002

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top