卡在组合框中

时间:2019-07-14 04:09:03

标签: excel vba

我在Excel UserForm中使用多个组合框通过引用到一个私有子目录中。 第一次选择时,它可以正常工作,但是对于下一行,我得到一个错误。

我坚持下去。

Private Sub frmFSPaper_Change()
    If frmFSPaper.Text <> "" Then
        Call BFSel(frmFSPaper, frmFSBF, frmFSGSM, frmFSMake)
    End If
End Sub

Private Sub frmFT1Paper_Change()
    If frmFT1Paper.Text <> "" Then
        Call BFSel(frmFT1Paper, frmFT1BF, frmFT1GSM, frmFT1Make)
    End If
End Sub

对于frmFSPaper来说,它工作正常,但是对于frmFT1Paper,我得到了一个错误。

下面是在SelBF.Clear

处引发未知错误的子项
Sub BFSel(ByRef SelPaper, ByRef SelBF, ByRef SelGSM, ByRef SelMake)
    Dim varPaperSel As Range
    Dim varBFSel As Range
    Dim sUsed As String, strSelected As String
    Dim LastRow As Long

    SelBF.Clear
    If SelPaper.ListIndex <> -1 Then
        strSelected = SelPaper.value
        LastRow = Worksheets("Master").Range("A" & Rows.Count).End(xlUp).Row
        Set varBFSel = Worksheets("Master").Range("A1:A" & LastRow)
        For Each varPaperSel In varBFSel
            If varPaperSel.value = strSelected Then
                varfound = False
                If SelBF.ListCount = 0 Then GoTo doAdd
                    Dim i As Integer
                    varfound = False
                    For i = 0 To SelBF.ListCount - 1
                        If LCase(SelBF.List(i)) = LCase(varPaperSel.Offset(, 1)) Then
                            varfound = True
                        End If
                    Next
doAdd:
                If varfound = False Then
                    SelBF.AddItem varPaperSel.Offset(, 1)
                End If
            End If
        Next varPaperSel
    End If
End Sub

0 个答案:

没有答案