过滤器功能 - 字符串类型不匹配问题

时间:2014-08-10 20:38:28

标签: vba excel-vba excel

使用过滤功能时出现类型不匹配的问题。我传递一个字符串来猜测除了if语句正常工作之外的所有内容。谁知道问题是什么?

Private Function perform_word(guess As String)

Dim area As Range
Dim hold_split() As String
Dim check_sum As String
Dim rng As String


Set area = Range("A1:G7")

ReDim hold_split(1 To Len(guess))

For i = 1 To Len(guess)
    hold_split(i) = Mid(guess, i, 1)
Next i

For i = 1 To area.Rows.Count
    For j = 1 To area.Columns.Count
    rng = area(i, j).Value
    If rng = Filter(hold_split, rng) Then           <<<<---- type mismatch here :(

    End If
    Next j
Next i

If check_sum = guess Then
    Debug.Print check_sum
End If
perform_word = hold_split
End Function

1 个答案:

答案 0 :(得分:1)

Filter函数的返回值是一个数组,而不是字符串。

您将返回值分配给rng,这是一个字符串。