Aretradeser
Board Regular
- Joined
- Jan 16, 2013
- Messages
- 176
- Office Version
- 2013
- Platform
- Windows
I want to use a ComboBox in a Userform to load data, the problem is that in the column where this data is located there are empty cells and the code I use doesn't work.
This is the VBA code I use (If there are no empty cells in the column it works):
What modification should I make in this code so that the ComboBox5 loads the records, as unique and ordered values, avoiding the empty cells?
This is the VBA code I use (If there are no empty cells in the column it works):
What modification should I make in this code so that the ComboBox5 loads the records, as unique and ordered values, avoiding the empty cells?
VBA Code:
Dim dar As Object
Dim va
Dim n As Integer
Private Sub UserForm_Initialize()
With Sheets("BDATOS")
n = .Range("B" & Rows.Count).End(xlUp).Row
va = .Range("C2:C" & n)
End With
Set dar = CreateObject("System.Collections.Arraylist")
End Sub
'
Private Sub ComboBox5_Enter()
Dim x
dar.Clear
For Each x In va
If Not dar.Contains(x) Then dar.Add CStr(x)
Next
dar.Sort
ComboBox5.List = dar.toArray()
End Sub