2011-11-09 168 views
0

我得到這個錯誤,我真的不知道爲什麼。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 

難道你們有什麼想法,爲什麼我得到無效的過程調用或參數?非常感謝!

+0

你能告訴我們如何這個值將會在單元格(rand,5)中,像這些(somename)那樣? – niko

回答

3

有可能

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 

因此,在檢查這些值第一

1

此代碼假定正在處理的單元格的內容ws.Cells(Rand,5).Value的格式爲「(此處爲某些文本)」。如果這種假設是錯誤的,則會發生上述錯誤。如果單元格是空的,要麼會發生這種情況(或)之前丟失或如果)自帶(

+0

哦......所以我必須在加載desch和inch變量之前看看它是否包含「(」。 –

相關問題