Show only items if "x"

collegeitdept

Board Regular
Joined
Nov 14, 2008
Messages
185
Does any on know of a formula that will only return the values in Column B only if it has an "X" in column A (without skipping a row).


Reference List

A B
x Item 1
Item 2
Item 3
Item 4
Item 5
x Item 6
x Item 7
x Item 8
Item 9
x Item 10



Returned values:

Item 1
Item 6
Item 7
Item 8
Item 10



Thanks.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
I'm fairly new to VBA myself, but I think this will get you started. Just paste in a standard module.
Create a backup before testing!

Sub Delete_xRows()
Application.ScreenUpdating = False
With ActiveSheet
.AutoFilterMode = False
.Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row).AutoFilter field:=1, Criteria1:="=x"
.Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row).Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
.AutoFilterMode = False
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Here is a non VBA solution.

Needs a dummy column

Column A = X's

Column B = Data to show

Column C =IF(A2="x",10^-6*ROW(),"")

Column D =IFERROR(INDEX($B$2:$B$11,MATCH(SMALL(OFFSET($C$2:$C$11,,,,),ROWS($A$2:A2)),$C$2:$C$11,0)),"")

Copy down. Change from B11 or C11 for the end of your range.

Steve=True
www.exceldashboardtemplates.com
 
Upvote 0
Does any on know of a formula that will only return the values in Column B only if it has an "X" in column A (without skipping a row).


Reference List

A B
x Item 1
Item 2
Item 3
Item 4
Item 5
x Item 6
x Item 7
x Item 8
Item 9
x Item 10



Returned values:

Item 1
Item 6
Item 7
Item 8
Item 10



Thanks.
E1, just enter:

=COUNTIF(A1:A10,"X")

E2: list

E3, control+shift+enter, not just enter, and copy down:

=IF(ROWS($E$3:E3)<=$E$1,INDEX($B$1:$B$10,SMALL(IF($A$1:$A$10="X",ROW($B$1:$B$10)-ROW($B$1)+1),ROWS($E$3:E3))),"")
 
Upvote 0
Hi Aladin,

Why doesn't the countif work inside the array? Seems like it should, but doesn't in testing.

Thanks

Steve=True
 
Upvote 0
Does any on know of a formula that will only return the values in Column B only if it has an "X" in column A (without skipping a row).
Returned where? Here is a macro which will output the list starting at the cell specified in the FirstCellToOutputTo constant (the Const statement)...

Code:
Sub GetXedItems()
  Const FirstCellToOutputTo As String = "D1"
  Range(FirstCellToOutputTo).EntireColumn.Clear
  On Error Resume Next
  Columns("A").SpecialCells(xlCellTypeConstants).Offset(, 1).Copy Range(FirstCellToOutputTo)
End Sub
 
Upvote 0
Hi Aladin,

Why doesn't the countif work inside the array? Seems like it should, but doesn't in testing.

Thanks

Steve=True

If you replace

$E$1

in the INDEX formula of E3 (see my post) with:

=COUNTIF($A$1:$A$10,"X")

the formula would still work. But we should avoid such repetitive calcs if we possibly can.
 
Upvote 0
Those formulas worked great.

Here's how I applied it to my workbook:


{=IFERROR(IF(ROWS(B$3:B3)<="",INDEX('[- Universal Invoice Form.xls]Sheet1'!$D$2:$D$992,SMALL(IF('[- Universal Invoice Form.xls]Sheet1'!$L$2:$L$992="x",ROW('[- Universal Invoice Form.xls]Sheet1'!$D$2:$D$992)-ROW('[- Universal Invoice Form.xls]Sheet1'!$D$2)+1),ROWS(A$3:B3))),""),0)}


However, that is looks for one variable (if) - if cells in column L = x

How do I add another condition

So the formula returns only values in Column D with the conditions that cells in Column L = X AND Column M = 2?


Thanks.
 
Upvote 0
Those formulas worked great.

Here's how I applied it to my workbook:


{=IFERROR(IF(ROWS(B$3:B3)<="",INDEX('[- Universal Invoice Form.xls]Sheet1'!$D$2:$D$992,SMALL(IF('[- Universal Invoice Form.xls]Sheet1'!$L$2:$L$992="x",ROW('[- Universal Invoice Form.xls]Sheet1'!$D$2:$D$992)-ROW('[- Universal Invoice Form.xls]Sheet1'!$D$2)+1),ROWS(A$3:B3))),""),0)}


However, that is looks for one variable (if) - if cells in column L = x

How do I add another condition

So the formula returns only values in Column D with the conditions that cells in Column L = X AND Column M = 2?


Thanks.

If you don't want to calculate a count in order to use it as a counter in the formula, you can just invoke:

=IFERROR(INDEX('[- Universal Invoice Form.xls]Sheet1'!$D$2:$D$992,SMALL(IF('[- Universal Invoice Form.xls]Sheet1'!$L$2:$L$992="x",ROW('[- Universal Invoice Form.xls]Sheet1'!$D$2:$D$992)-ROW('[- Universal Invoice Form.xls]Sheet1'!$D$2)+1),ROWS(B$3:B3))),0)

Augmented with column M = 2, we get:

=IFERROR(INDEX('[- Universal Invoice Form.xls]Sheet1'!$D$2:$D$992,SMALL(IF('[- Universal Invoice Form.xls]Sheet1'!$L$2:$L$992="x",IF('[- Universal Invoice Form.xls]Sheet1'!$M$2:$M$992=2,ROW('[- Universal Invoice Form.xls]Sheet1'!$D$2:$D$992)-ROW('[- Universal Invoice Form.xls]Sheet1'!$D$2)+1)),ROWS(B$3:B3))),0)
 
Upvote 0

Forum statistics

Threads
1,224,568
Messages
6,179,572
Members
452,927
Latest member
whitfieldcraig

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