UserForm ComboBox Exclude Blanks

Tuta

Board Regular
Joined
Nov 6, 2008
Messages
85
Office Version
  1. 365
Platform
  1. Windows
All,

I have a dynamic range serving as a RowSource for a list that populates a ComboBox in a userform.

I only want the user to see the non-blank items in that range.

I am also using the selection to run a application.match off of so I need to retain it to pre-populate some textboxes.

How can I handle this problem?

Code:
Private Sub ComboBox1_Change()

Dim x As Variant

x = Application.Match(ComboBox1, Range("SelectionListing"), 0)

    TextBox1.Text = Cells(x, 15).Value
    TextBox2.Text = Cells(x, 16).Value
    TextBox3.Text = Cells(x, 17).Value

End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
If your dynamic range is named 'DynRange', and refers to a single column, try the following code that needs to be placed in the module for the userform...

Code:
Private Sub UserForm_Initialize()
    Dim Rng As Range
    Dim i As Long
    Me.ComboBox1.RowSource = ""
    Set Rng = Range("DynRange")
    For i = 1 To Rng.Rows.Count
        If Rng(i) <> "" Then
            Me.ComboBox1.AddItem Rng(i)
        End If
    Next i
End Sub
 
Upvote 0
Domenic -- that worked beautifully !

Many thanks!
 
Upvote 0

Forum statistics

Threads
1,216,100
Messages
6,128,829
Members
449,471
Latest member
lachbee

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