【发布时间】:2011-04-25 02:52:22
【问题描述】:
我试图从我的程序 callLum() 中调用 sub Lum(),要求 Lum 分别获取值 11、12、13,但似乎 Lum 无法识别我之前在 callLum 中对计数器的定义(),如下图所示。原因是在我的实际主脚本中,我有一个很长的 For-next 循环,如果我不使用 Msgbox 中断循环,程序在到达“next”时似乎找不到“For”字。这就是为什么我最终结束了主脚本,然后创建了一个简单的子脚本来调用它。
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
【问题讨论】: