Extract Rows with "X" in column A (Index Match solution?)

lawi227

Board Regular
Joined
Mar 17, 2016
Messages
123
I have a set of data (A1:H658). In column A, I want to put an "X" next to any rows that I want to pull over.

My traditional way of doing this is to do an IF statement that says IF(A1="X",B1,""). But this returns a lot of blanks. For example, if I have ~500 rows of data, and I put an "X" next to 200 rows, then I have 300 rows of blank data. I would traditionally highlight this list, and filter out the blanks.

There has to be a better way of only returning rows of data (from column B to H) to another worksheet, if there is an X in column A.

Here are my headers and columns:
ABCDEFGH
Include in Assessment?Ref #SC, OF, or SCOFExcellence CategoryFunctionSub-FunctionProcessDescription
X1SCPeoplePurchaseBuyerHRBLAH BLAH BLAH

<tbody>
</tbody>

Does that make sense?

Thanks so much! I will forever being using this formulas, as I do a lot of this! Thanks!
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Is filtering on column A and then copying and pasting an option? If not, you can try something like this:


Excel 2010
ABCDEFGH
1Include in Assessment?Ref #SC, OF, or SCOFExcellence CategoryFunctionSub-FunctionProcessDescription
2X1SCPeoplePurchaseBuyerHRBLAH BLAH BLAH
32OFabcde
4X3SCOFfghij
Sheet1



Excel 2010
ABCDEFG
1Ref #SC, OF, or SCOFExcellence CategoryFunctionSub-FunctionProcessDescription
21SCPeoplePurchaseBuyerHRBLAH BLAH BLAH
33SCOFfghij
4
Sheet2
Cell Formulas
RangeFormula
A2{=IFERROR(INDEX(Sheet1!B$2:B$4,SMALL(IF(Sheet1!$A$2:$A$4="X",ROW(Sheet1!$A$2:$A$4)-1),ROW(1:1))),"")}
Press CTRL+SHIFT+ENTER to enter array formulas.


Drag the formula down and to the right. Adjust ranges as needed.
 
Last edited:
Upvote 0
Thank you! Can you provide an explanation briefly of how that formula works so I can build upon it in the future?

Also, if I do any filtering, will that mess up the formulas? Let's say I want to only view "HR" in column F on sheet 2.

Is filtering on column A and then copying and pasting an option? If not, you can try something like this:

Excel 2010
ABCDEFGH
1Include in Assessment?Ref #SC, OF, or SCOFExcellence CategoryFunctionSub-FunctionProcessDescription
2X1SCPeoplePurchaseBuyerHRBLAH BLAH BLAH
32OFabcde
4X3SCOFfghij

<tbody>
</tbody>
Sheet1



Excel 2010
ABCDEFG
1Ref #SC, OF, or SCOFExcellence CategoryFunctionSub-FunctionProcessDescription
21SCPeoplePurchaseBuyerHRBLAH BLAH BLAH
33SCOFfghij
4

<tbody>
</tbody>
Sheet2

Array Formulas
CellFormula
A2{=IFERROR(INDEX(Sheet1!B$2:B$4,SMALL(IF(Sheet1!$A$2:$A$4="X",ROW(Sheet1!$A$2:$A$4)-1),ROW(1:1))),"")}

<tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>



Drag the formula down and to the right. Adjust ranges as needed.
 
Last edited:
Upvote 0
Thank you! Can you provide an explanation briefly of how that formula works so I can build upon it in the future?

You're welcome. The formula is similar to an INDEX MATCH formula but the key difference is that an INDEX MATCH formula returns the first match (where column A has an "X") where this one returns all of the matches.

The ROW(1:1) of the SMALL function is what changes the "k" (match number) when you drag the formula down.

Note that the range in the beginning of the INDEX function has the columns as relative (no "$", will change when dragging across) and the rows as absolute ("$", will not change).
 
Upvote 0
I am trying to use the same formula on a different set of data, and I had a follow-up question. When I use the formula, it does not return the correct cell reference. Let's say instead of "X", I search for "OU". I get a list of of data and all of them are off by the same number of rows. For example, If I select "Engr" and I'm supposed to get data from cell A11, A12, and A22, the formula ends up returning values in A18, A19, and A29. So they are all off by 7 rows. Here is the updated formula I am using (which is inserted into cell A4 on a sheet called "Engr":
{=IFERROR(INDEX('Roll-up'!A$9:A$87,SMALL(IF('Roll-up'!$AG$9:$AG$87="Engr",ROW('Roll-up'!$AG$9:$AG$87)-1),ROW(1:1))),"")}

Do you know why that is? Thanks so much for your help and sorry to have a follow up question.

You're welcome. The formula is similar to an INDEX MATCH formula but the key difference is that an INDEX MATCH formula returns the first match (where column A has an "X") where this one returns all of the matches.

The ROW(1:1) of the SMALL function is what changes the "k" (match number) when you drag the formula down.

Note that the range in the beginning of the INDEX function has the columns as relative (no "$", will change when dragging across) and the rows as absolute ("$", will not change).
 
Upvote 0
I am trying to use the same formula on a different set of data, and I had a follow-up question. When I use the formula, it does not return the correct cell reference. Let's say instead of "X", I search for "OU". I get a list of of data and all of them are off by the same number of rows. For example, If I select "Engr" and I'm supposed to get data from cell A11, A12, and A22, the formula ends up returning values in A18, A19, and A29. So they are all off by 7 rows. Here is the updated formula I am using (which is inserted into cell A4 on a sheet called "Engr":
{=IFERROR(INDEX('Roll-up'!A$9:A$87,SMALL(IF('Roll-up'!$AG$9:$AG$87="Engr",ROW('Roll-up'!$AG$9:$AG$87)-1),ROW(1:1))),"")}

Do you know why that is? Thanks so much for your help and sorry to have a follow up question.

Welcome back! This is probably due to the fact that the formula assumes that the data starts in row 2. Try this instead (changes highlighted in red):

=IFERROR(INDEX('Roll-up'!A$9:A$87,SMALL(IF('Roll-up'!$AG$9:$AG$87="Engr",ROW('Roll-up'!$AG$9:$AG$87)-(ROW('Roll-up'!$AG$9)-1)),ROWS($A$1:$A1))),"") Ctrl Shift Enter
 
Upvote 0
Thank you so much! Last modification: can I include an "isblank" into the formula so that if a cell isblank, it just returns a blank, rather than a zero?

Much appreciated!! And thanks for the quick reply!
 
Upvote 0
Thank you so much! Last modification: can I include an "isblank" into the formula so that if a cell isblank, it just returns a blank, rather than a zero?

Much appreciated!! And thanks for the quick reply!

Sure, try this one (changes to formula from post #6 in red):

=IFERROR(INDEX('Roll-up'!A$9:A$87,SMALL(IF(('Roll-up'!$AG$9:$AG$87="Engr")*('Roll-up'!A$9:A$87<>""),ROW('Roll-up'!$AG$9:$AG$87)-(ROW('Roll-up'!$AG$9)-1)),ROWS($A$1:$A1))),"") Ctrl Shift Enter
 
Upvote 0
That's perfect! I'll have to add this formula to my arsenal! Much appreciated.

Sure, try this one (changes to formula from post #6 in red):

=IFERROR(INDEX('Roll-up'!A$9:A$87,SMALL(IF(('Roll-up'!$AG$9:$AG$87="Engr")*('Roll-up'!A$9:A$87<>""),ROW('Roll-up'!$AG$9:$AG$87)-(ROW('Roll-up'!$AG$9)-1)),ROWS($A$1:$A1))),"") Ctrl Shift Enter
 
Upvote 0

Forum statistics

Threads
1,216,073
Messages
6,128,645
Members
449,461
Latest member
kokoanutt

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