How do I maintain List Box values

DBD

New Member
Joined
May 5, 2004
Messages
25
Hi, I 'm a little new to excel.

Summary: I need help looping through values in a range of cell when I open a workbook to poulate a list box.

I have two combo boxes on one sheet. The change event of listbox1 queries a db base and returns a list of branches into another worksheet ("Sheet2") . I then loop the the returned values an populate listbox2. This works fine , except when I re-open the workbook the listbox2 is not populated. I've tried to call my sub it Workbook_open, but I an error.

"Comple Error in hidden Module: ThisWorkbook"

I have Listbox1 that I populate on workbook_Open
example:
Code:
    Worksheets("Sheet1").Listbox1.AddItem "Alanta"
    Worksheets("Sheet1").Listbox1.AddItem "Boston"
    Worksheets("Sheet1").Listbox1.AddItem "New York"

  call LoadTeamcenter ("Sheet2")' I get an error here
' here is sub that is in Sheet 1 module. So maybe my question should be How can i force the following sub on open.
Code:
Public Sub LoadTeamcenter(strWorksheetFrom As String)

  Dim ws As Worksheet
  
  Set ws = Worksheets(strWorksheetFrom)
'get number of Branches reteuned
intTeamcenterCount = GetRowCnt("Sheet2", "A", 2)


ReDim ArrTeamcenterNum(intTeamcenterCount)
ReDim ArrTeamcenterDesc(intTeamcenterCount)

r = 2
For i = 1 To intTeamcenterCount
               
          ArrTeamcenterNum(i) = ws.Cells(r, 1)
          ArrTeamcenterDesc(i) = ws.Cells(r, 2)
           
       r = r + 1
       Next
  
   Worksheets("Sheet1").cboTeamcenter.Clear
   
 For i = 0 To UBound(ArrTeamcenterDesc)
 
   Worksheets("Sheet1").cboTeamcenter.AddItem ArrTeamcenterDesc(i)
 

Next i
  
End Sub

Thanks in advance
DBD
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,203,234
Messages
6,054,278
Members
444,714
Latest member
excel2782

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top