1
之外的變量我試圖從我的程序callLum()中調用子Lum(),要求Lum分別獲得值11,12,13,但看起來像Lum無法識別我之前在callLum()中定義的計數器,如下面的腳本所示。原因是在我的實際Main腳本中,我有一個長For-next循環,如果我不打斷Msgbox的循環,程序似乎在到達「next」時找不到「For」字樣。這就是爲什麼我最終包裝了主要腳本,後來創建了一個簡單的子程序來調用它。Excel-VBA - 調用Sub並要求它調用定義在Sub
Sub callLum()
Dim counter As Integer
Dim LR As Long, j As Long
counter = 10
'checking number of rows in column A
LR = Range("A" & Rows.Count).End(xlUp).Row
For j = 1 To LR
If Not IsEmpty(Range("A" & j)) And Not IsEmpty(Range("B" & j)) Then _
counter = counter + 1
Call Lum
Next j
MsgBox "THE END"
End Sub
Sub Lum()
MsgBox "Counter value is " & counter
End Sub
它的工作原理,當我更改「呼叫Lum」到「呼叫Lum(byval計數器)」在callLum子也,謝謝。 – 2011-04-27 03:33:19