VBA 将增量值添加到组合框中
VBA add incremented values into combobox
|我想知道如何通过值的增量从一个值到另一个值填充组合框的项目列表?
我现在做的方式是手工通过:
LowerFilmWidth_ComboBox.AddItem "300"
在此示例中,我尝试以 1 为增量将值从 300 添加到 650
有人可以分享这样做的代码吗?
请尝试下一个代码:
Sub AddIncrementedNrCombo()
Dim i As Long, arr(350)
For i = 300 To 650
arr(i - 300) = i
Next i
LowerFilmWidth_ComboBox.list = arr
End Sub
已编辑:
允许以不同增量递增的版本:
Sub AddIncrementedNrCombo()
Dim i As Long, arr(350), k As Long, inc As Long
inc = 10 'it can be calculated
For i = 300 To 650 Step inc
arr(k) = i: k = k + 1
Next i
ReDim Preserve arr(k - 1)
LowerFilmWidth_ComboBox.list = arr
End Sub
编辑2:
Sub AddIncrementedNrComboVar()
Dim i As Long, arr(), k As Long, mN As Long, mX As Long, inc As Long
mN = 300 'min
mX = 650 'max
inc = 10
ReDim arr(mX - nm)
For i = mN To mX Step inc
arr(k) = i: k = k + 1
Next i
ReDim Preserve arr(k - 1)
LowerFilmWidth_ComboBox.list = arr
End Sub
如果你想花哨,你可以使用类似的东西:
LowerFilmWidth_ComboBox.List = [Row(300:650)]
但为了将来参考,您应该了解 For
循环,您可以在其中 Step
在指定的时间间隔(默认为 1)
For x = 300 To 650 'Step 1
LowerFilmWidth_ComboBox.AddItem x
Next
|我想知道如何通过值的增量从一个值到另一个值填充组合框的项目列表? 我现在做的方式是手工通过:
LowerFilmWidth_ComboBox.AddItem "300"
在此示例中,我尝试以 1 为增量将值从 300 添加到 650
有人可以分享这样做的代码吗?
请尝试下一个代码:
Sub AddIncrementedNrCombo()
Dim i As Long, arr(350)
For i = 300 To 650
arr(i - 300) = i
Next i
LowerFilmWidth_ComboBox.list = arr
End Sub
已编辑:
允许以不同增量递增的版本:
Sub AddIncrementedNrCombo()
Dim i As Long, arr(350), k As Long, inc As Long
inc = 10 'it can be calculated
For i = 300 To 650 Step inc
arr(k) = i: k = k + 1
Next i
ReDim Preserve arr(k - 1)
LowerFilmWidth_ComboBox.list = arr
End Sub
编辑2:
Sub AddIncrementedNrComboVar()
Dim i As Long, arr(), k As Long, mN As Long, mX As Long, inc As Long
mN = 300 'min
mX = 650 'max
inc = 10
ReDim arr(mX - nm)
For i = mN To mX Step inc
arr(k) = i: k = k + 1
Next i
ReDim Preserve arr(k - 1)
LowerFilmWidth_ComboBox.list = arr
End Sub
如果你想花哨,你可以使用类似的东西:
LowerFilmWidth_ComboBox.List = [Row(300:650)]
但为了将来参考,您应该了解 For
循环,您可以在其中 Step
在指定的时间间隔(默认为 1)
For x = 300 To 650 'Step 1
LowerFilmWidth_ComboBox.AddItem x
Next