Link to home
Start Free TrialLog in
Avatar of zoltix
zoltix

asked on

VBA: How to fill in a comboxbox from excell sheet?

I must do a little program in excell vba but I must fill in a combox from excell sheet with distinct value.  Could you help me.
EX:
LLII
PASE
PASE
QSDF
QSDF
GDQD
wxcv
wxcv
wxcv
wxcv



In my combobox I neeed only LLII,PASE,QSDF,GDQD,wxcv(it s important have just one)?
Thank
ASKER CERTIFIED SOLUTION
Avatar of lyonst
lyonst
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here's a simple macro:

Sub FillCombo()
Dim sht As Worksheet
Dim lRow As Long
Dim sValue As String

    Set sht = Sheets(2) 'data sheet
    lRow = 1 'startrow
   
    On Error Resume Next
    With ComboBox1
        .Clear
        .Style = fmStyleDropDownList
        Do
            sValue = sht.Cells(lRow, 1).Value
            If Len(sValue) = 0 Then Exit Do 'exit if no value
            .Text = sValue
            If Err.Number <> 0 Then 'not added yet
                .AddItem sValue
            End If
            Err.Clear
            lRow = lRow + 1
        Loop
    End With
End Sub

D'Mzzl!
RoverM