RowSource
是为
柱状的
范围:如果将其指定为
行状
范围你只能得到第一个单元格
但你可以用
List
性质
ComboBox
对象,并用通过
行状
范围:
Private Sub UserForm_Activate()
Dim res As String
Dim cell As Range: Set cell = Sheets("Pomocne").Range("B2")
Dim endcell As Range
Do Until IsEmpty(cell)
Set endcell = cell
Set cell = cell.Offset(0, 1)
Loop
res = "Pomocne!B2:" & Replace(endcell.Address, "$", "")
obor_combo.List = Application.Transpose(Range(res).Value)
End Sub
可以简化为:
Private Sub UserForm_Activate()
With Sheets("Pomocne")
obor_combo.List = Application.Transpose(.Range("B2", .Cells(2, .Columns.Count).End(xlToLeft)).Value)
End With
End Sub