View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default Populating combobox in custom toolbar

Bill,

I am glad you got it working. However you raised a couple of questions/issues...
1. Module level variables in Class modules are private. So code in another
module won't know about it.
2. I would not use a Range variable with the same name as a Name object.
3. Even if you declare a public variable as a Range (in a standard module),
you must still Set the variable to a specific range before you can refer to it.
4 If you have a named range, that name will be available throughout the project.
So Worksheets(x).Range("rgUniqueStations") should work in all modules.
5. Or if you want to use that named range location on another sheet, you can...
Dim strRngName as String
strRngName = Worksheets(x).Range("rgUniqueStations").Address
Set rngList = Worksheets(y).Range("strRngName")
For lngN = 1 to rngList.Count
---
Jim Cone
San Francisco, USA


"Bill_excelforum"
wrote in message...
Thanks, Jim. That works now.

As part of opening my workbook, I do a .CopyFromRecordset to a range.
Then I name the range "rgUniqueStations". ( And I have Public
rgUniqueStations As Range in the Declarations at the top of my
ThisWorkbook module.) My expectation was that I would use that range in
conjunction with .AddItem.

Jim, you declared another range:

Set rngList = Worksheets(1).Range("A1:A3181")

And used it in this code:

For lngN = 1 To 3181
cmdComBox.AddItem rngList(lngN).Value
Next

I tried substituting my range rgUniqueStations, but that didn't work at
all. My aim in doing that is to avoid hard coding the length of the
range (3181) because the number of stations in the list could change
from time to time.

Anyway, thanks much for your help.
Bill


--
Bill_excelforum
------------------------------------------------------------------------
Bill_excelforum's Profile: http://www.excelforum.com/member.php...o&userid=32280
View this thread: http://www.excelforum.com/showthread...hreadid=526912