VBA Excel Adding Range With Dynamic Size To Combobox List
<p>I have a range within the workbook that I'd like to set to the list of items in a Combobox from one of my Userforms. The issue is the Range can be any size. I currently handle the zero case by exiting the <code>Sub</code>, but when there's only one element in the range.</p>

<p>When there's one element, instead of returning an array of elements, it only returns a single <code>String</code> element and the listbox gives me an error:
`Run-time error '381': Could not set the List property. Invalid property array index'. Is there anyway to handle this besides creating an exception for the case where there's only one element?</p>

<p>Here's the code:
Edit: Fixed program to accurately represent problem.</p>

<pre><code>Private Sub UserForm_Activate()
    Dim formList As Variant
    Dim lastRow As Long
    lastRow = getLastRowInCol(Sheets("HiddenVariables"), "B")
    If lastRow = 0 Or lastRow = 1 Then Exit Sub 
    formList = Sheets("HiddenVariables").Range("B2:B" &amp; lastRow).value 'If lastRow =2 then run-time error 381 is thrown
    Me.ComboBox.list = formList
End Sub
</code></pre>

<p><a href="https://i.stack.imgur.com/aA6ba.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aA6ba.png" alt="Same issue with solution"></a></p>