Your macro is on the right track, however the I think I can clarify
exactly what I desire from my nested if effort:
Data Table
Column A Col C Col E Col K
ORIGIN DESTIN AIR DESIRED
DFW IAH 8W 1
PHX IAH HP 1
DTW IAH NW 1
MKE IAH NW 0
PIT IAH CO 1
IAH DTW CO 0
Desired Conditions (Col K)
1. Keep (desired value=1) all NW flights with DTW, or MEM, or MSP in
origin/destin.
2. Remove (desired value=0) all other NW flights.
3. Remove (desired value=0) all CO flights with DTW, or MEM, or MSP in
origin/destin.
4. Keep (desired value=1) all other CO flights.
5. Keep (desired value=1) all other airline flights.
We succeed if these conditions are met
Okay, having put it that way, it's a lot clearer. This code *should*
work (it reproduced your results with the 6 examples you gave). Just a
little note, all I did was translate the conditions you listed into
actual code. You probably could have done it if you had just sat down
and thought it out. Also, in your original post, the Excel formula was
looking at 2 cells and doing a numeric comparison (apparently dates),
but this particular chunk of code does not do that.
To use this, call it within the cell like any other function, with the
parameter being the row it's on (use the ROW() function so you don't
have to keep track) like this:
=nocoffeebreak4u(ROW())
If you don't want even that, use the sub that follows the function.
Function noCoffeeBreak4U(rowNum As Long) As Integer
Select Case UCase(Cells(rowNum, 5).Value)
Case "NW"
Select Case UCase(Cells(rowNum, 1))
Case "DTW", "MEM", "MSP" 'condition 1
noCoffeeBreak4U = 1
Case Else
Select Case UCase(Cells(rowNum, 3))
Case "DTW", "MEM", "MSP" 'condition 1
noCoffeeBreak4U = 1
Case Else 'condition 2
noCoffeeBreak4U = 0
End Select
End Select
Case "CO"
Select Case UCase(Cells(rowNum, 1))
Case "DTW", "MEM", "MSP" 'condition 3
noCoffeeBreak4U = 0
Case Else
Select Case UCase(Cells(rowNum, 3))
Case "DTW", "MEM", "MSP" 'condition 3
noCoffeeBreak4U = 0
Case Else 'condition 4
noCoffeeBreak4U = 1
End Select
End Select
Case Else 'condition 5
noCoffeeBreak4U = 1
End Select
End Function
Sub call4Coffee()
For x = 2 To 30001
Cells(x, 11).Value = noCoffeeBreak4U(x)
Next
End Sub