在Excel 2010中键入不匹配错误

时间:2014-10-11 20:46:56

标签: vba excel-vba excel-2010 excel

我在Excel 2010中通过A列中的文本值运行此宏。错误消息为" Type Mismatch"。它是编码问题还是与Excel 2010相关?因为它在Excel 2003中运行良好。

宏识别常见字符串并提供带有单词和计数的输出。

Sub Common_words()
    Dim vArray As Variant
    Dim lLoop As Long
    Dim rCell As Range

    With CreateObject("Scripting.Dictionary")
        For Each rCell In Range("A1", Cells(Rows.Count, "A").End(xlUp))
            vArray = Split(rCell.Value, " ")
            For lLoop = LBound(vArray) To UBound(vArray)
                If Not .exists(vArray(lLoop)) Then
                    .Add vArray(lLoop), 1
                Else
                    .Item(vArray(lLoop)) = .Item(vArray(lLoop)) + 1
                End If
            Next lLoop
        Next rCell
        Range("B1").Resize(.Count).Value = Application.Transpose(.keys)
        Range("C1").Resize(.Count).Value = Application.Transpose(.items)
    End With
End Sub

1 个答案:

答案 0 :(得分:0)

添加对Microsoft Scripting Runtime的引用。