Excel 过滤器样式复选框中的VBA-#不适用和(空白)

Excel 过滤器样式复选框中的VBA-#不适用和(空白),excel,vba,userform,Excel,Vba,Userform,我试图创建过滤器样式的复选框,但不知道如何处理#N/A(显示为错误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(

我试图创建过滤器样式的复选框,但不知道如何处理#N/A(显示为
错误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
适用于空白,但不适用于#N/A

当我试着-

ClientType = Sht.Range(StartCell, Sht.Cells(LastRow, StartCell.Column)).Text
当我运行
UniqueType(ClientType(I,1))=1时,我得到一个
运行时错误“13”:类型不匹配


有没有更聪明的方法来做我想做的事?

在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

有没有一种方法可以像我们筛选专栏时那样包含它们?我不明白你的意思,请进一步澄清。对不起。当我们对Excel工作表中的列应用Data>Filter时,如果列中有空格和错误,我们会在选项中看到
(空格)
#N/a
。有没有办法做到这一点?