combobox不进入正确的单元格

我有以下function:

Sub AddComboBox(ByVal strName As String, ByVal strTableName As String, ByVal iColumn As Integer, ByVal rIndex As Integer, ByVal cIndex As Integer, Optional ByVal strSetTo As String) Dim vArr As Variant vArr = GetTableKeys(strTableName, iColumn) pos = Application.Match(strSetTo, vArr, False) Worksheets("C&E Editor").DropDowns.Add(xlDropDown, Left:=Cells(rIndex, cIndex).Left, Top:=Cells(rIndex, cIndex).Top, Width:=Cells(rIndex, cIndex).Width, Height:=Cells(rIndex, cIndex).Height).Select With Selection For i = LBound(vArr) To UBound(vArr) .AddItem vArr(i) Next i .Name = "cmb" + strName On Error GoTo setPos .ListIndex = pos End With Exit Sub setPos: pos = 1 End Sub 

被称为:

 AddComboBox "Controller", "controllers", 1, CurrentRowIndex, 3 

但是,每次调用该函数时,combobox都会添加到正确的行中,但始终在第1列中。

我有一个函数添加checkbox,是非常相似的,它使用相同的variablesrIndexcIndex但它把checkbox在正确的列。

一切工作,除了定位。

checkbox的代码是…

  Sub AddCheckBox(ByVal rIndex As Integer, ByVal cIndex As Integer, ByVal OnOff As Integer, Optional ByVal caption As String = "") Worksheets("C&E Editor").CheckBoxes.Add(Cells(rIndex, cIndex).Left, Cells(rIndex, cIndex).Top, Cells(rIndex, cIndex).Width, Cells(rIndex, cIndex).Height).Select With Selection .caption = caption .Value = OnOff .LinkedCell = Cells(rIndex, 14) .Display3DShading = True End With End Sub 

您需要删除xlDropDown部分:

 Worksheets("C&E Editor").DropDowns.Add(Left:=Cells(rIndex, cIndex).Left, Top:=Cells(rIndex, cIndex).Top, Width:=Cells(rIndex, cIndex).Width, Height:=Cells(rIndex, cIndex).Height).Select