簡體   English   中英

VBA中的無效過程調用或參數錯誤

[英]Invalid procedure call or argument error in 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的格式為“(此處為某些文本)”。 如果該假設是錯誤的,將發生上述錯誤。 如果單元格為空,或者(或)丟失,或者)在(之前),則會發生這種情況。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM