关于使组合框(2列)为空的错误381

时间:2015-10-16 13:58:45

标签: excel vba excel-vba combobox userform

我在cmbSaveAndNew_click之后的目标是保持用户窗体打开,所有内容都为空(除了没有选定值的填充cmbTest)

Private Sub UserForm_Initialize()

Dim i As Integer
Dim j As Integer

i = 2
j = 0

frmTest.cmbKinderen.Clear
frmTest.cmbKinderen.ColumnCount = 2

    While Sheets("shtGegevens").Cells(i, 1) <> ""
        frmTest.cmbTest.AddItem (sheets(1).cells(i, 1))
        frmTest.cmbTest.Column(1, j) = Sheets(1).Cells(i, 1)
        i = i + 1
        j = j + 1
    Wend

    cmbThing.AddItem "Yes"
    cmbThing.AddItem "No"

End Sub

第二分:

Private Sub cmbTest_Change()

Dim i As Integer
Dim j As Integer

i = frmTest.cmbTest.Column(1) 'ERROR HERE

If Sheets(1).Cells(i, 5) = "Yes" Then
    frmTest.cmbThing.Value = "Yes"
ElseIf Sheets(1).Cells(i, 5) = "No" Then
    frmTest.cmbThing.Value = "No"
Else
    frmTest.cmbThing.Value = ""
End If

End Sub

直到这里,一切正常。我的组合框被填充,我的'组合'组合框值取决于我在cmbTest等中选择的内容。

问题出现在以下子项之后:

Private Sub cmdSaveAndNew_Click()

Dim i As Integer

i = frmTest.cmbTest.Column(1)

'write something in sheets

'current wrong solution:
cmbTest.value = "" 'ERROR BECAUSE OF THIS

End Sub

错误即时获取是一个错误381,类似于“无法获取属性列.inpertytrix的索引无效”(已翻译)

如何在不收到此错误的情况下取消选择'所选的cmbTest值?

0 个答案:

没有答案