Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default public array

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?



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default public array

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

"Circe" wrote:

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?




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default public array

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default public 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)


"Circe" wrote in message
...
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??




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default public array

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

"Bob Phillips" wrote:

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)


"Circe" wrote in message
...
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??







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default public array

okokokokokok !
i got it! thx!



"Jim Thomlinson" ha scritto nel
messaggio ...
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

"Bob Phillips" wrote:

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)


"Circe" wrote in message
...
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??







  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default public array

:-).

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

Regards

Bob

"Jim Thomlinson" wrote in message
...
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

"Bob Phillips" wrote:

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)


"Circe" wrote in message
...
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??







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dim vs. Public Jason Morin Excel Programming 7 January 27th 05 01:13 PM
Array of Public Arrays Hari Prasadh Excel Programming 1 January 21st 05 03:42 PM
How to reference a public array (declared in module) from a proced Amzee Excel Programming 3 January 11th 05 06:26 PM
declaring a public array JT[_2_] Excel Programming 3 July 27th 04 11:18 PM
Public Array Brent McIntyre Excel Programming 5 September 23rd 03 12:53 AM


All times are GMT +1. The time now is 12:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"