代码之家  ›  专栏  ›  技术社区  ›  phil_t

过滤器样式复选框中的VBA-#N/A和(空白)

  •  0
  • phil_t  · 技术社区  · 6 年前

    Error 2042 )和(空白)。

    我的代码的相关部分是-

    'Read Client Type Column
    ClientType = Sht.Range(StartCell, Sht.Cells(LastRow, StartCell.Column))
    
    'Find unique client names
    Set UniqueType = CreateObject("Scripting.Dictionary")
    
    For i = LBound(ClientType, 1) To UBound(ClientType, 1)
        UniqueType(ClientType(i, 1)) = 1
    Next i  
    
    Temp = UniqueType.Keys()
    
    Cntr = 1
    
    On Error Resume Next
    For Each j In Temp
        Set Cbx = UserForm1.Controls.Add("Forms.CheckBox.1")
        Cbx.Caption = j
        Cbx.Left = 15
        Cbx.Top = 10 + (15 * (Cntr - 1))
        Cntr = Cntr + 1
    Next j
    

    If UniqueType.Exists("") Then
        UniqueType.Remove ""
        UniqueType.Add "(Blanks)", 1
    End If
    

    适用于空白但不适用于不适用。

    当我试着-

    ClientType = Sht.Range(StartCell, Sht.Cells(LastRow, StartCell.Column)).Text
    

    Run-time error '13': Type mismatch 当我跑的时候 UniqueType(ClientType(i, 1)) = 1 .

    1 回复  |  直到 6 年前
        1
  •  1
  •   DisplayName    6 年前

    OP澄清后编辑:

    'Read Client Type Column
    Set UniqueType = CreateObject("Scripting.Dictionary")
    Dim cell As Range
    For Each cell In Sht.Range(StartCell, Sht.Cells(LastRow, StartCell.Column))
        'Find unique client name
        UniqueType(cell.Text) = 1
    Next
    
    Temp = UniqueType.Keys()
    
    '... rest of your code