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: 8
Last edited by a moderator:

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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,223,869
Messages
6,175,088
Members
452,611
Latest member
bls2024

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