IF Statement Help Needed

sshaffer99

Board Regular
Joined
Sep 29, 2010
Messages
111
Hello,</SPAN>

I am trying to create an IF statement for my “Notes” column but I can’t figure out how.</SPAN>

I have 3 Yes/No Columns that show exceptions - LoanExcept, AddrExcept,GARExcept. I’d like to populate 1 Note field that indicates which columns have a “Yes” - see example below.</SPAN>

I assume I can use an IF statement in my Notes column, but not sure how to code it. Any ideas? </SPAN>
Thanks for your help.

Below are the combinations:
A<o:p></o:p>
B<o:p></o:p>
C<o:p></o:p>
D<o:p></o:p>
LoanExcept<o:p></o:p>
AddrExcept<o:p></o:p>
GARExcept<o:p></o:p>
Notes<o:p></o:p>
Y<o:p></o:p>
N<o:p></o:p>
N<o:p></o:p>
Exception for Loan<o:p></o:p>
Y<o:p></o:p>
Y<o:p></o:p>
N<o:p></o:p>
Exception for Loan, Addr<o:p></o:p>
Y<o:p></o:p>
Y<o:p></o:p>
Y<o:p></o:p>
Exception for Loan, Addr, GAR<o:p></o:p>
N<o:p></o:p>
Y<o:p></o:p>
N<o:p></o:p>
Exception for Addr<o:p></o:p>
N<o:p></o:p>
Y<o:p></o:p>
Y<o:p></o:p>
Exception for Add, GAR<o:p></o:p>
N<o:p></o:p>
N<o:p></o:p>
Y<o:p></o:p>
Exception for GAR<o:p></o:p>

<TBODY>
</TBODY>
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Use column E as a helper column. In E2:
=IF(A2="Y","Loan","")&IF(B2="Y",", Addr","")&IF(C2="Y",", GAR","")
fill down.
In D2:
=IF(E2<>"","Exception for "&IF(LEFT(E2,1)=",",MID(E2,3,100),E2),"")
Fill down.
Hide column E
 
Upvote 0
Assuming that the data starts on row 2, so your first formula should appear in D2, you could place this formula in cell D2:
Code:
=IF(COUNTIF(A2:C2,"Y")>0,"Exception for " & IF(A2="Y","Loan, ","") & IF(B2="Y","Addr, ","") & IF(C2="Y","Gar, ",""),"")
Now, this gets you almost what you want, except there will be a comma and space at the end of each string (where there is at least one "Y"). If this is a problem, you can do one of the following:
1. Use this as a "helper" column, and place this in cell E2 (you can then hide column D, if you like):
Code:
=IF(LEN(D2)>0,LEFT(D2,LEN(D2)-2),"")
2. Combine these two formulas in one cell (simply use the formula above in step 1, but replacing every reference to cell D2 with the formula originally posted for cell D2 above). That formula will look a bit messy, and could be a bear to edit, if you ever need to.

Quite frankly, my preferred method of handling situations like this is to create my own function using VBA that does exactly what I want, and is easier to view and edit. The function would look something like this:
Code:
Function MyConcat(myRange As Range) As String


    Dim myString As String
    Dim myPhrase As String
    Dim cell As Range
    
'   Loop through all cells in Range
    For Each cell In myRange
'       Check to see if value is "Y"
        If cell = "Y" Then
'           If so, capture the value you want to return
            Select Case cell.Column
                Case 1  'for column A
                    myPhrase = "Loan, "
                Case 2  'for column B
                    myPhrase = "Addr, "
                Case 3  'for column C
                    myPhrase = "Gar, "
            End Select
'           Build second part of string
            myString = myString & myPhrase
        End If
    Next cell
    
'   If any Y values found, return entire phrase
    If Len(myString) > 0 Then
        MyConcat = "Exception for " & Left(myString, Len(myString) - 2)
    Else
        MyConcat = ""
    End If
    
End Function
Then, to use it on my spreadsheet, simply enter this formula in cell D2:
Code:
=MyConcat(A2:C2)
So that gives you a few options to work from. There are some brilliant formula gurus on this forum who if the see this, may be able to come up with a better formula, but all these options I provided will work.
 
Upvote 0
try
="exception for "&LOOKUP(A2&B2&C2,{"NNN","NNY","NYN","NYY","YNN","YYN","YYY"},{"none","GAR","Addr","Add, GAR","Loan","Loan, Addr","Loan, Addr, GAR"})
 
Upvote 0
Nice solution Martin!
 
Upvote 0
there are actually 8 combos plus 1 for all blanks
Excel Workbook
ABC
1yyy
2yyn
3yny
4ynn
5nyy
6nny
7nyn
8nnn
Sheet1

so maybe


=IF(A1&B1&C1="","","Exception for "&LOOKUP(A1&B1&C1,{"nnn","nny","nyn","nyy","ynn","yny","yyn","yyy"},{"NONE","Gar","Addr","Addr,Gar","Loan","Loan,Gar","Loan,Addr","Loan,Addr,Gar"}))
 
Upvote 0
Here's another approach as an Array formula. It treats the selection as a binary number and uses Choose.

=CHOOSE(SUM((A7:C7="Y")*2^(COLUMN(A7:C7)-1))+1,"NONE","Loan","Addr","Loan,Addr","Gar","Loan,Gar","Addr,Gar","Loan,Addr,Gar")

confirm with CTRL + SHIFT + Enter.

I don't think it's any better than Martin's solution, but I had an idea and wanted to see if I could make it work :).
 
Upvote 0
then another rethink
="exception for "&SUBSTITUTE(TRIM(IF(A2="y","loan"," ")&" "&IF(B2="y","addr"," ")&" "&IF(C2="y","gar",""))," ",",")
 
Upvote 0
Wow, GREAT Ideas! Thank you all so much. I ended up using Martin's idea, but may go to Joe4's idea to creating a function if it gets much more complicated. I didn't think of the situation if any of the 3 fields are null, or blank. I may make them mandatory, or add some logic to say if A or B or C are blank/Null, then "Missing data".

Again, thank you all.
 
Upvote 0

Forum statistics

Threads
1,217,367
Messages
6,136,148
Members
449,994
Latest member
Rocky Mountain High

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