Excel-VBA - Call Sub and ask it to regconise variable defined outside the Sub?

Up vote 1 down vote favorite share g+ share fb share tw.

I've tried to call a sub Lum() from my program callLum(), to ask Lum to get value 11,12,13 respective, but seem like the Lum can't recognise my earlier definition of counter in callLum(), illustrate as script below. The reason being is that in my actual Main script I have a long For-next loop, if I don't interrupt the loop with Msgbox, the program seem like cannot find the "For" word when it reached "next". That's why I end up wrap up the main script and later on create a simple sub to call it.

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 excel-vba link|improve this question edited Apr 26 '11 at 3:31Johan23.6k51555 asked Apr 25 '11 at 2:52Kwai Lum1114 0% accept rate.

Change Lum to be: Sub Lum(ByVal counter as Integer) MsgBox "Counter value is " & counter End Sub For your loop, rather than testing every element of the range separately, specify the range as a Ax:Ay where x and y are filled in by your loop.

It works, when I change "call Lum" to "call Lum (byval counter)" in callLum sub also, thanks. – Kwai Lum Apr 27 '11 at 3:33.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions