【问题标题】:Invalid procedure call or argument error in VBAVBA 中的无效过程调用或参数错误
【发布时间】:2011-11-09 12:22:27
【问题描述】:

我收到此错误,我真的不知道为什么。

我有以下代码:

Rand = 2
LRand = ws.Cells(Rows.Count, 6).End(xlUp).Row
Do While Rand <> LRand + 1
    If ws.Cells(Rand, 4).Value = "" Then
        desch = InStr(ws.Cells(Rand, 5).Value, "(")
        inch = InStr(ws.Cells(Rand, 5).Value, ")")
        ws.Cells(Rand, 4).Value = Mid(ws.Cells(Rand, 5).Value, desch + 1, inch - desch - 1) 'here is the error
    End If
Rand = Rand + 1
Loop

你们知道为什么我得到无效的过程调用或参数吗?非常感谢!

【问题讨论】:

  • 你能告诉我们像这些(somename)这样的单元格(rand,5)中的值吗?

标签: excel vba error-handling


【解决方案1】:

有可能

 if desch = 0
      or 
 if inch = 0

 desch = instr('this may return zero')
 inch  = instr('when it doesnt find the substring')

 so putting them in mid functions results like these

 mid(string,0,0) results error  
 mid(string(0,2) results error
 mid(string(2,0) results error

所以首先检查这些值

【讨论】:

    【解决方案2】:

    此代码假定正在处理的单元格的内容 ws.Cells(Rand, 5).Value 采用“(此处的一些文本)”形式。如果这个假设是错误的,就会发生上述错误。如果单元格为空、缺少 ( 或 ) 或 ) 在 (.

    【讨论】:

    • 哦...所以我必须在加载 desch 和 inch 变量之前查看它是否包含“(”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多