combobox showing all rows not just filtered out ones

NewVeryNew

New Member
Joined
Jan 18, 2022
Messages
15
Office Version
  1. 2011
Platform
  1. Windows
I am trying to filter out columns based on combo box drop down list but the second combo box show all the rows in the column and not just the ones the where filtered out.

Any clues?

VBA Code:
Option Explicit
Private Sub ComboBox1_Change()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Detailed")
Dim i As Integer
Dim n As Integer

n = Application.WorksheetFunction.Match(Me.ComboBox1.Value, sh.Range("3:3"), 0)
Me.ComboBox2.Clear
For i = 4 To Application.WorksheetFunction.CountA(sh.Cells(3, n).EntireColumn)
    Me.ComboBox2.AddItem sh.Cells(i, n).Value
Next i

End Sub


Private Sub UserForm_Activate()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Detailed")

Dim i As Integer

Me.ComboBox1.Clear
For i = 1 To Application.WorksheetFunction.CountA(sh.Range("3:3"))
    Me.ComboBox1.AddItem sh.Cells(3, i).Value
    'ComboBox1.Text = "SubCat"
    
Next i

End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Assuming that the full range from which the combobox can get its data has a name (or address) then fill the combobox as follows:

VBA Code:
    Dim rC As Range, rA As Range
    
    Me.ComboBox2.Clear
    
    For Each rA In Range("YouFilterRange").SpecialCells(xlCellTypeVisible).Areas
        For Each rC In rA.Cells
            Me.ComboBox2.AddItem rC.Value
            
        Next rC
    Next rA
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,934
Members
449,094
Latest member
teemeren

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