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

Finding the right help in "Help" has been a problem for me. Thank you.

"Norman Jones" wrote:

Hi Cody,

Does the public variable not work between code in worksheets
and code in modules?



In Module1
'-------------

Option Explicit
Public MyCol As Collection

Sub Demo()
Dim i As Long

Set MyCol = New Collection

For i = 1 To 10
MyCol.Add "Book" & i, CStr(i)
Next i

End Sub

In Sheet1 Module
--------------------
Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("A1:A10")) Is Nothing Then
Target(1, 2).Value = MyCol(Target.Row)
End If
End Sub


Run the Demo sub to initialize the public Collection.

Then in Sheet1, make successive entries in cells A1 to A10. Now look At
cells B1:B10.

Look in VBA help at 'Public Statement' and 'Understanding Scope and
Visibility'.

---
Regards,
Norman



"Cody" wrote in message
...
Does the public variable not work between code in worksheets and code in
modules? The code is started and finished in the worksheets and uses
modules.

"Cody" wrote:

That is basically how my code is running right now. However, when the
code
in the second module is running the collection does not even appear in
the
locals window as a variable in memory. I tried changing the code to an
array
and I am still having the same problem.

In terms of my code:
The first module opens the second module which loads a form. After the
user
inputs a value in the form the value is added to the array. This loops
until
a certain value is reached. The sub is then exited and goes back to the
code
in the first module. The array does not appear in the locals window in
the
first module.

Thanks for any help!

"Norman Jones" wrote:

Hi Cody,

Apparently collection is not a valid type for Public variables so I
need
to
know how to pass collections between modules.


In Module1
'-------------

Option Explicit
Public MyCol As Collection

Sub Demo()
Dim i As Long

Set MyCol = New Collection

For i = 1 To 10
MyCol.Add "Book" & i, CStr(i)
Next i
End Sub


In Module2
'-------------

Option Explicit
Sub TestIt()
Dim i As Long

For i = 1 To MyCol.Count
Debug.Print MyCol(i)
Next i

End Sub

---
Regards,
Norman



"Cody" wrote in message
...
I have created a collection in a module and I would like to use the
values
in
the collection in another module.

Apparently collection is not a valid type for Public variables so I
need
to
know how to pass collections between modules.

Thanks for any help.






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
How many hyperlinks can be in collection? mikebres Excel Programming 2 June 24th 05 03:15 PM
Collection Todd Huttenstine Excel Programming 4 December 17th 04 09:41 PM
worksheet collection issue Mark Kubicki Excel Programming 2 November 18th 03 02:44 AM
Is a Collection the best option? Patrick Molloy Excel Programming 0 September 1st 03 10:05 AM
Is a Collection the best option? Stuart[_5_] Excel Programming 5 August 31st 03 09:51 PM


All times are GMT +1. The time now is 12:00 AM.

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"