public array

  • Thread starter Thread starter Circe
  • Start date Start date
C

Circe

I have this script

public tMonths
Sub LoadMonths()

Set shtMesi = Workbooks(w).Sheets(sht)
LastRow = shtM.Cells.SpecialCells(xlCellTypeLastCell).Row
LastCol = shtM.Cells(1, 255).End(xlToLeft).Column

ReDim tMonths(LastRow, LastCol)
For R = 1 To LastRow
For C = 1 To LastCol
tMonths(R, C) = shtMesi.Cells(R C)
Next
next

end sub


If i write this

public tMonths
Sub LoadMonths()
Dim lRange As Range
Dim tMonths as Variant
Set lRange = workbooks(w).sheets(sht).Range(range)
tMonths = lRange.value
end sub

and i try to call from another macro i get error using tMonths
What do i wrong?
 
First off I notice that you have declared tMonths both Public at the top of
the procedue and again within the procedure. The Dim tMonths will override
the Public tMonths and your public variable will not be initialized.

HTH
 
First off I notice that you have declared tMonths both Public at the top
of
the procedue and again within the procedure. The Dim tMonths will override
the Public tMonths and your public variable will not be initialized.
And how can i pass to another macro the array??
 
If you just declare it Public outside of the macro, and remove the same
variable in the macro, then the other macro can use that same macro.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
I am having a little trouble following your answer Bob. Normally you are much
more lucid than I am.

tMonths is global and can be read from or written to by any macro. So just
remove the Dim statement and you are off to the races.

HTH
 
okokokokokok !
i got it! thx!



Jim Thomlinson said:
I am having a little trouble following your answer Bob. Normally you are
much
more lucid than I am.

tMonths is global and can be read from or written to by any macro. So just
remove the Dim statement and you are off to the races.

HTH
 
:-).

I was just trying to reinforce your point Jim, but I think I had too many
macros and too few variables.

Regards

Bob
 
Back
Top