View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Robert[_16_] Robert[_16_] is offline
external usenet poster
 
Posts: 29
Default Declaring Variables

Can anybody confirm how to declare variables so that they
are accessible outside the procedure in which they had
been declared. If I use Dim, it only appears to work
within its own procedure. I also tried Static and it
doe'nt appear to work. A simplified version of the
procedures are belo. The main procedure is Transfer_Prices
which calls soln_check. Variables like
soln_count,rnum,cnum declared in Transfer_Prices do not
seem to be recognised in Soln_check.

Do the variables also have to be included in the call ie
procedure e.g. Soln_check(soln, soln_count) ?

Sub Transfer_Prices()
'
Static soln_rnum As Integer
Static soln_cnum As Integer
Static soln_count As Integer
Static rnum As Integer
Static cnum As Integer
Static soln As String

rnum = 11
cnum = 14
soln_rnum = 11
soln_cnum = 17
soln_count = 0

soln_rnum = soln_rnum + 1
If Cells(soln_rnum, soln_cnum + 2).Value < 0 Then
Soln_check (soln)
Cells(soln_rnum, soln_cnum - 1).Value = soln_count
End If
Cells(soln_rnum, soln_cnum).Select
End Sub


Sub Soln_check(soln)
Do While rnum < 30
rnum = rnum + 1
If ActiveCell.FormulaR1C1 = soln Then
soln_count = soln_count + 1
ElseIf ActiveCell.FormulaR1C1 < soln Then
Cells(rnum, cnum).Select
End If
Loop
Range("O39").Select
End Sub