gpt4 book ai didi

vba - Excel VBA 运行时错误 '13' : Type mismatch

转载 作者:行者123 更新时间:2023-12-03 02:24:17 30 4
gpt4 key购买 nike

我不太擅长 VBA,但突然间,我开始收到此错误。如果您能找到错误所在,请告诉我。我对这一点很执着。我确实到处搜索并发现了很多类似的帖子,但解决方案似乎总是非常特定于代码。各位专家将不胜感激。

这是我的代码:

Sub FindSimilar()
Dim phrases As Range, phrase As Range
Dim terms As Range, term As Range
Dim matches As String
Dim words() As String

'ensure this has the correct sheet names for your workbook
Set phrases = ThisWorkbook.Worksheets("Export").Range("B2:B3500")
Set terms = ThisWorkbook.Worksheets("Topics").Range("D767:D967")

For Each term In terms
matches = ""
words() = Split(term.Value)

For i = 0 To UBound(words, 1)
If Len(words(i)) > 2 Then
Select Case words(i)
Case "examplewords", "blacklist"
Case Else
For Each phrase In phrases
If InStr(1, phrase.Value, words(i)) Then
matches = matches & phrase & "/"
End If
Next phrase
End Select
End If

我真的不知道为什么

Run-time error 13: Type mismatch

正在被抛出。

断点出现在以下几行:

        matches = ""

还有

       Set terms = ThisWorkbook.Worksheets("Topics").Range("D773:D779")

还有

       For i = 0 To UBound(words, 1)

最佳答案

运行时错误“13”:循环遍历从工作表收集的大量值的中途类型不匹配几乎总是由于遇到工作表错误代码而导致。

Export!B2:B3500 或 Topics!D767:D967 中是否存在任何工作表错误代码(例如 #N/A、#VALUE! 等)?

I found one single #N/A cell. It was not there as an error but as a pasted value :-( It's working now!

通过以下步骤,您可以快速找到一长列值(甚至整个工作表)中的任何工作表错误。

  1. 选择整列。如果您想查看整个工作表,只需选择任何单个单元格即可。2、按F5,然后单击特殊。
    enter image description here
  2. 选择公式并仅选中错误。
    enter image description here
  3. 单击“确定”。
    enter image description here

通过以下一项或两项操作也可以发现工作表错误。

<range>.SpecialCells(xlCellTypeConstants, xlErrors)
<range>.SpecialCells(xlCellTypeFormulas, xlErrors)

关于vba - Excel VBA 运行时错误 '13' : Type mismatch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48957607/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com