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

我得到这个错误,我真的不知道为什么。

我有以下一段代码:

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 

所以首先检查这些值

这段代码假设正在处理的单元格的内容ws.Cells(Rand,5).Value的格式是“(某些文本在这里)”。 如果这个假设是错误的,则会发生上述错误。 如果单元格为空,或者(或)缺less或者如果)在之前(),则会发生这种情况。