Jens
Jens

Reputation: 185

Add more than one range to combobox

I have a combobox and I want to add E1 and then another range somewhere between E2 and E13 depending on some variables. But what happens is that the entire range is added, E1:E13. This is the code:

Sheets("GraphChoice").MonthComboBox.AddList = Sheets("FormInfo").Range("E1", "E" & startmonth + 1 & ":E13")

Is it possible to add more than one range to a combobox?

Upvotes: 0

Views: 94

Answers (1)

YasserKhalil
YasserKhalil

Reputation: 9538

Try this code

Sub Test()
Dim a, e, r As Range, i As Long
With Sheets("FormInfo")
    Set r = Application.Union(.Range("E1"), .Range("E4:E13"))
    ReDim a(1 To r.Cells.Count)
    For Each e In r
        i = i + 1
        a(i) = e
    Next e
    Sheets("GraphChoice").MonthComboBox.List = a
End With
End Sub

Upvotes: 1

Related Questions