Sort out data using autofilter

YingFa

Board Regular
Joined
Nov 4, 2019
Messages
63
Hi experts. I currently have the following code (see below) in a worksheet I use at work. I would like to streamline the process to filter data by removing the command button to show all data and include "all" in the combobox. When "all" is selected in the combobox it should filter/show all data. Do you have any idea on how to do this?

Combobox Fill Data

Private Sub ComboBox1_DropButt*******()
Me.ComboBox1.ListFillRange = "Name"
End Sub

Advance Filter

Private Sub ComboBox1_Change()
On Error Resume Next
Sheet1.Range("E2") = Me.ComboBox1.Value
a = Application.WorksheetFunction.CountA(Sheet1.Range("A:A"))
Sheet1.Range("A" & 1, "D" & a).AdvancedFilter xlFilterInPlace, _
Sheet1.Range("E1:E2")
End Sub

Show All Data

Private Sub CommandButton1_Click()
On Error Resume Next
ActiveSheet.ShowAllData
End Sub
 

Some videos you may like

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

YingFa

Board Regular
Joined
Nov 4, 2019
Messages
63
[FONT=Arial, Tahoma, Helvetica, FreeSans, sans-serif]This should be the first line of the code above
[/FONT]Private Sub Combobox1_DropButt*******()
 

Watch MrExcel Video

Forum statistics

Threads
1,122,168
Messages
5,594,632
Members
413,919
Latest member
ZaxAlchemist

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
Top