Filter Status Using Checkbox

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





VBA 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
 

Attachments

  • Screenshot 2024-07-29 171126.png
    Screenshot 2024-07-29 171126.png
    12.2 KB · Views: 7
Last edited by a moderator:

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
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





VBA 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
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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