我正在尝试在用户填充的单元格的右侧插入一个“PASS / FAIL”标准的下拉列表。将按顺序从上到下填充单元格。以下是我到目前为止的情况:
Sub ComboBoxPassFail()
Dim i As Integer
Dim rng As Range
i = 4
For Each c In Worksheets("Inspection Report").Range("A4", Range("A4").End(xlDown)).Cells
If c.Value <> "" Then
Set rng = c.Offset(0, 14)
Top = rng.Top
Left = rng.Left
ActiveSheet.OLEObjects.Add(classtype:="forms.combobox.1", Left:=Left, Top:=Top, Width:=8, Height:=15).Insert
i = i + 1
End If
Next c
i = 4
End Sub
我的主要问题来自处理组合框。
答案 0 :(得分:0)
一些事情
top
和left
是VBA中的保留字。您不能将它们用作变量Long
而不是Integer
。顺便说一句,我没有在代码中看到使用i
。.Insert
无效声明。这是你在尝试的吗?
Sub ComboBoxPassFail()
Dim rng As Range, c As Range
Dim rngTop As Double, rngLeft As Double
For Each c In Worksheets("Inspection Report").Range("A4", Range("A4").End(xlDown)).Cells
If c.Value <> "" Then
Set rng = c.Offset(0, 14)
rngTop = rng.Top
rngLeft = rng.Left
'~~> You may want to decide on a more appropriate width value? :)
ActiveSheet.OLEObjects.Add classtype:="forms.combobox.1", _
Left:=rngLeft, Top:=rngTop, _
Width:=8, Height:=15
End If
Next c
End Sub