You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Excel VBA运行时错误'13':类型不匹配问题求助

Troubleshooting Excel VBA Run-time Error '13' on a Line with "And And"

Hey there, let’s dig into why you’re hitting that annoying Run-time Error '13' (Type Mismatch) on the line with what looks like double And operators. I’ve debugged tons of these issues, so here are the most common culprits to check first:

  • You’ve got a typo with duplicate And operators
    VBA doesn’t allow back-to-back And keywords. For example, if you meant to write If X > 0 And Y < 10 And Z = "OK" Then but accidentally typed If X > 0 And And Z = "OK" Then, the second And gets treated as an invalid identifier (like a variable name that doesn’t exist). When VBA tries to evaluate this, it expects a Boolean (True/False) value but gets garbage, triggering the type mismatch.

  • Your conditions aren’t all Boolean values
    Even if the "And And" is a typo (like you missed a condition between them), the real issue might be that one of the expressions you’re joining with And isn’t a proper True/False statement. For example:

    ' ❌ Error: Range("B1") is a Range object, not a Boolean
    If Range("A1").Value > 100 And Range("B1") And Range("C1").Value = "Approved" Then
        ' Your code here
    End If
    

    Every part separated by And needs to be a full Boolean condition. Fix it by spelling out each check clearly:

    ' ✅ Fixed: Each segment evaluates to True/False
    If Range("A1").Value > 100 And Range("B1").Value = "Ready" And Range("C1").Value = "Approved" Then
        ' Your code here
    End If
    
  • Cell values are causing implicit type conversion failures
    If your conditions reference cells, empty values, text vs. number mismatches, or error values (like #N/A) can break the logical check. For example, comparing a text cell to a number, or trying to evaluate an error cell in a condition:

    ' ❌ Error: If A1 has text "123" or is empty, this can trigger type mismatch
    If Range("A1").Value > 100 And Range("B1").Value = "Yes" Then
    

    Add checks to validate cell values first:

    ' ✅ Fixed: Verify cell type before comparing
    If IsNumeric(Range("A1").Value) And Range("A1").Value > 100 And Range("B1").Value = "Yes" Then
    

If you can share the exact line of code (or a simplified version that reproduces the error), we can narrow this down even more. But these fixes should cover the most common scenarios with this specific error.

内容的提问来源于stack exchange,提问作者DomainsFeatured

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:32:50