Excel VBA运行时错误'13':类型不匹配问题求助
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
Andoperators
VBA doesn’t allow back-to-backAndkeywords. For example, if you meant to writeIf X > 0 And Y < 10 And Z = "OK" Thenbut accidentally typedIf X > 0 And And Z = "OK" Then, the secondAndgets 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 withAndisn’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 IfEvery part separated by
Andneeds 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 IfCell 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" ThenAdd 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

