请为我提供此问题的解决方案。我是宏的新手,我无法执行此操作。
我试过这段代码
Sub BindCombo()
Dim Last
Last = Sheets("Defect Dump").Cells(2, 2).End(xlDown).Row
With ComboBox1
For Row = 2 To Last
.AddItem Sheets("Defect Dump").Cells(Row, 1)
Next Row
End With
End Sub
但是此代码显示对象错误
您需要创建一个对象引用ComboBox
试试这个
Sub BindCombo()
Dim Last As Long, rw As Long
Dim sh As Worksheet
Dim cb As ComboBox
Set sh = Sheets("Defect Dump")
Last = sh.Cells(2, 2).End(xlDown).Row
' get Combobox on "project sheet" sheet
Set cb = Sheets("project sheet").Shapes("ComboBox1").DrawingObject.Object
With cb
.Clear ' remove any existing items
For rw = 2 To Last
.AddItem sh.Cells(rw, 1)
Next
End With
End Sub