Auto Filter in Excel

Status
Not open for further replies.

iggyboy29

New Member
Joined
Jul 29, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi everyone can anyone help me to put code in checkbox to filter a list box based on check box is check ,for example if i uncheck DONE, i wish the DONE is hide in the list box

HERES MY CODE

Private Sub ComboBox1_AfterUpdate()
Call Data_Filter
End Sub

Private Sub ComboBox1_Change()
Call Data_Filter
End Sub

Private Sub UserForm_Initialize()

Dim lr As Long
lr = Application.WorksheetFunction.CountA(Sheet1.Range("A:A"))

If lr = 1 Then lr = 2

With Me.ListBox1
.ColumnCount = 2
.ColumnHeads = True
.ColumnWidths = "60,60"
.RowSource = "Sheet1!A2:B" & lr
End With

Call Combobox_List

End Sub

Sub Combobox_List()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("DROPDOWN")

Dim i As Integer

Me.ComboBox1.Clear
Me.ComboBox1.AddItem ""

For i = 1 To Application.WorksheetFunction.CountA(sh.Range("A:A"))
Me.ComboBox1.AddItem sh.Range("A" & i)
Next i

End Sub

Sub Data_Filter()
Application.ScreenUpdating = False

Dim dsh As Worksheet
Set dsh = ThisWorkbook.Sheets("Sheet1")

Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Sheet3")

dsh.AutoFilterMode = False
sh.AutoFilterMode = False
sh.UsedRange.ClearContents

'''''' AUTO FILTER ''''''

If Me.ComboBox1.Value <> "" Then
dsh.UsedRange.AutoFilter 1, Me.ComboBox1.Value
End If

'If Me.CheckBox1.Value = True Then
' dsh.UsedRange.AutoFilter 2, "DONE"
'End If

'If Me.CheckBox2.Value = True Then
'dsh.UsedRange.AutoFilter 2, "ON GOING"
'End If

'If Me.CheckBox3.Value = True Then
'dsh.UsedRange.AutoFilter 2, "NOT YET"
'End If

dsh.UsedRange.Copy
sh.Range("A1").PasteSpecial xlPasteValuesAndNumberFormats

dsh.AutoFilterMode = False

'''''' DISPLAY DATA IN LIST BOX ''''''

Dim lr As Long
lr = Application.WorksheetFunction.CountA(Sheet3.Range("A:A"))

If lr = 1 Then lr = 2

With Me.ListBox1
.ColumnCount = 2
.ColumnHeads = True
.ColumnWidths = "60,60"
.RowSource = "Sheet3!A2:B" & lr
End With

End Sub

HERE IS MY FILE
 

Attachments

  • Screenshot 2024-07-29 171126.png
    Screenshot 2024-07-29 171126.png
    12.2 KB · Views: 6

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Duplicate to: Filter Status Using Checkbox

In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.

In relation to your question here, I have closed this thread so please continue in the linked thread. If you do not receive a response, you can "bump" it by replying to it yourself, though we advise you to wait 24 hours before doing so, and not to bump a thread more than once a day.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,224,812
Messages
6,181,088
Members
453,021
Latest member
Justyna P

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