Excel Filter based on cell

natheplas

Board Regular
Joined
Aug 28, 2016
Messages
97
Hi Forum,

I have a table containing data A2:K173, there could be more rows added so it could grow to A2:K400. Row 2 is the table headers.

What I want to achieve is in Cell B1, someone can write a number or product code and then the table filters by that product code.

All the product codes are in Column D (D3:D175).

I've googled it for a while now and I can't get anything, others have done it, but I cant replicate it.

It's essentially filter column D, on work sheet 'Ordering Info' by cell value B1.

Could we do it so if nothings in there it doesn't filter, but if there is a value typed it filters.

Thank you. It's really appreciated.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Not Target.Address(0, 0) = "B1" Then Exit Sub
   If Me.AutoFilterMode Then Me.AutoFilterMode = False
   If Target.Value <> "" Then
      Range("A2").AutoFilter 4, Target.Value
   End If
End Sub
This needs to go in the sheet module
 
Upvote 0

Forum statistics

Threads
1,217,248
Messages
6,135,472
Members
449,938
Latest member
gameboybin

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