Userform Combibox (dropdown) box populating

sassriverrat

Well-known Member
Joined
Oct 4, 2018
Messages
655
Good Morning,

I've got a data array, which my userform combibox/dropdown menu references.

I have 100 available "slots" for data input in the array, but I don't use all of them. The initialize code (below) works well for the combibox to populate it. However, being as I only use about 20 of the rows currently, and the other 80 are for future expansion, I was wondering:

Is it possible to have the combibox only populate with rows that have information? Meaning if a row is blank (the unused rows), don't show them in the dropdown?

Code:
ComboBox1.List = Application.Index(Sheets("Ports").Range("B3:G102").Value, Evaluate("row(1:100)"), Array(1, 6))
 

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).
If you want to load data from row 3 to the last row with data according to column B, it can be like this:

VBA Code:
Private Sub UserForm_Initialize()
  Dim lr As Long
  lr = Sheets("Ports").Range("B" & Rows.Count).End(xlUp).Row
  ComboBox1.List = Application.Index(Sheets("Ports").Range("B3:G" & lr).Value, Evaluate("row(1:" & lr - 2 & ")"), Array(1, 6))
End Sub



But if you have blank intermediate cells, then it could be like this:

Code:
Private Sub UserForm_Initialize()
  Dim sh As Worksheet, i As Long
  Set sh = Sheets("Ports")
  For i = 3 To 102
    If sh.Range("B" & i).Value <> "" Then
      ComboBox1.AddItem sh.Range("B" & i)
      ComboBox1.List(ComboBox1.ListCount - 1, 1) = sh.Range("G" & i)
    End If
  Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,748
Messages
6,180,721
Members
452,995
Latest member
isldboy

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