Hide blanks in userform combobox

nicolewh

Well-known Member
Joined
Aug 7, 2009
Messages
554
I have a combobox1 that has a row source for a table called "List" column called "List on Form"

The column "List on Form" has some blank spaces. Is there any way I can have the blank spaces hidden within the dropdown list of the combobox1?

So far I use the userform application Row Source and place in it "List
[List on Form]" but of course there are blank spaces in the userform dropdown list due to the blank spaces in the source.

Any help would be very appreciated.

Nicole
 
It looks like you almost answered your own question. Using the same code and range example from 8½ years ago with the same assumptions of the list in column C of the same worksheet and the values as constants, further assuming your reference to str2 is a string type variable (not what is in cell STR2):

Private Sub UserForm_Initialize()
Dim cell As Range
For Each cell In Columns(3).SpecialCells(2)
If cell.value = str2 Then AddItem cell.Value
Next cell
End Sub

thanks for the code but this doesn't work as i want it

my previous code show everything from Database IU Column N(14) and i need to filter that with the extra IF Cell value is same as str2 show this row (for now i have 5 rows but when its finished i got over 1000 rows)
Code:
Private Sub UserForm_Initialize()
Dim cell As Range
With Worksheets("Database IU")
For Each cell In .Range("N2:N" & .Cells(Rows.Count, 3).End(xlUp).Row)
If Len(cell.Value) > 0 Then Filters.AddItem cell.Value
Next cell
End With
End Sub
JDDVLtn.jpg

the code you made shows me the company name of column C(3)
Code:
Private Sub UserForm_Initialize()
Dim cell As Range
For Each cell In Columns(3).SpecialCells(2)
If cell.Value = str2 Then Filters.AddItem cell.Value
Next cell
End Sub
8oiR4Fg.jpg
 
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
What i try to do is like this

Code:
show all values of Column N where Column C valua = str2 and skip the blank cells like the previous code above
 
Upvote 0
now i have this code it works for me the only thing is it wont filter the empty cells out
how can i add the skip empty cells code of your to this one ?

Code:
Sub Filtersload()

Dim RowMax As Integer
Dim wsh As Worksheet
Dim countExit As Integer
Dim CellCombo2 As String
Dim i As Integer

Set wsh = ThisWorkbook.Sheets("Database IU")
RowMax = wsh.cells(Rows.Count, "C").End(xlUp).Row
'find last row of sheet in column A

Filters.Clear
'clear all value of comboBox2

With Filters
    For i = 1 To RowMax
        If wsh.cells(i, "C").Value = str2 Then
        'Just show value of mapping with column A
        .AddItem wsh.cells(i, "N").Value
        Else
        End If
    Next i
End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

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