public array

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?
 
G

Guest

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
 
C

Circe

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??
 
B

Bob Phillips

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)
 
G

Guest

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
 
C

Circe

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
 
B

Bob Phillips

:).

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

Regards

Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top