0

I have a list of data in excel consisting of "Yes" and "No".

I need an IF statement that will only act on cells with the "Yes" value, and skip any cells with the "No" value.

For context, the 'value if true' clause of my IF statement is an indexmatchmatch which needs to return a value in the sheet based on the "Yes" or "No".

I understand this could have a simple solution using VBA, so if anyone has an excel based solution or VBA based solution they would be equally helpful.

I can add columns and rows to the dataset I am working with if needs be.

2
  • I've tried the excel solution myself but my vba skills aren't up to the task, I've tried and failed. Commented May 25, 2017 at 11:11
  • This doesn't work? =IF(A1="Yes",<YourIndexMatchMatchFormulaHere>,"") Commented May 25, 2017 at 17:50

2 Answers 2

1

Try this:

Sub YesNo()
Dim lRow As Long
Dim sht As Worksheet
Set sht = Worksheets("Tabelle1")

lRow = sht.Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lRow
    If sht.Cells(i, 1).Value = "True" Then 'Modify Column
        'Your Code
    End If
Next i
End Sub
Sign up to request clarification or add additional context in comments.

Comments

1

Use VBA to achieve it

Assume in sheet , you have

A   Yes
B   Yes
C   No
A   Yes
B   No
C   Yes
A   No
B   No

After running the macro, Sheet 2 will have only those rows which have yes in Sheet1. Please modify the code based on your requirement

Sub g()
Dim lastRow As Long
Dim sheet As Worksheet
Set sht = Worksheets("Sheet1")
Set sht1 = Worksheets("Sheet2")

lRow = sht.Cells(Rows.Count, 1).End(xlUp).Row
Dim j As Long
j = 1
For i = 1 To lRow

    If sht.Cells(i, 2).Value = "Yes" Then
        sht1.Cells(j, 1).Value = sht.Cells(i, 1).Value
        j = j + 1
    End If
Next i
End Sub

4 Comments

The issue is that where there are false values, i want to ignore them and look for the next "Yes" in the list and apply the indexmatchmatch to that
If I understand correctly, you have a list of rows with a column value either "Yes" or "No" and in the next column you want to display "indexmatchmatch" if the value is "Yes" else blank. =IF(<cell_no>="Yes","indexmatchmatch",""). You can drag the formula for all the rows.
They are not adjacent, what I need is a column fully populated (no gaps) with the indexmatchmatch formula I have, but right now because of the IF statement that applies to the "Yes" or "No" field I have gaps where the IF statement is picking up "No". If I applied the IF statement to the "No"'s as well then my data would be inconsistent.
I have modified the answer to achieve it by using VBA. Hope it will help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.