I have the following 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
being called by:
AddComboBox "Controller", "controllers", 1, CurrentRowIndex, 3
But every time the function is called the ComboBox is added to the correct row, but is always in column 1.
I have a function to add check boxes and is very similar, it uses the same variables rIndex
and cIndex
but it puts the checkboxes in the proper columns.
Everything works except the positioning.
The checkbox code is...
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
答案 0 :(得分:0)
您需要删除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