excel - VBA中的无效过程调用或参数错误

标签 excel vba error-handling

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

我有以下代码:

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

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

最佳答案

有可能的

 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

所以首先检查那些值

关于excel - VBA中的无效过程调用或参数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8064958/

相关文章:

vba - 如何使用vba创建二进制序列?

vba - 在Excel中添加列

excel - Powershell - 将 .XLS 文件转换为 .XLSX

excel - 如何计算某个字符串在不同工作表上出现的次数?

excel - 通过 GUI 脚本排序保存 SM37 行?

ms-access - 如何在 MS Access 中重载 Form_MouseWheel()?

VBA:复制和粘贴数据行的最快方法

python - Python 3.6 : Using object instance name for raising errors

java - 空 JTextField 并添加数字

error-handling - puppet systemctl在云端启动puppetserver错误-CentOS7