Populating list boxes from Excel (1 Viewer)

Spooky

Registered User.
Local time
Today, 14:07
Joined
Jun 11, 2012
Messages
18
Currently I pull all my listbox data from a word document. I would like to pull it directly from a (source) excel spreadsheet as Im assuming its more efficient and would save me a couple of steps.

Im trying to modify some code that I dont know a lot about :)
The example below works, but Im trying to change it to work with my spreadsheet (not the sample one)

I know to change the workbook name etc, but the only part Im not sure about relates to the name mySSRange like so : Range("mySSRange").Rows.

What does "mySSRange" refer to?

Code:
  Set xlApp = CreateObject("Excel.Application")
  Set xlWB = xlApp.Workbooks.Open("c:\temp\sourceSpreadsheet.xls")
  Set xlWS = xlWB.Worksheets(1)
  cRows = xlWS.Range("mySSRange").Rows.Count - xlWS.Range("mySSRange").Row + 1
  ListBox1.ColumnCount = 3
 
  With Me.ListBox1
    For i = 2 To cRows
      .AddItem xlWS.Range("mySSRange").Cells(i, 1)
      'Use .List method to populate the remaining columns
      .List(.ListCount - 1, 1) = xlWS.Range("mySSRange").Cells(i, 2)
      .List(.ListCount - 1, 2) = xlWS.Range("mySSRange").Cells(i, 3)
    Next i
  End With
  Set xlWS = Nothing
  Set xlWB = Nothing
  xlApp.Quit
  Set xlApp = Nothing
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 07:07
Joined
Jan 20, 2009
Messages
12,851
Select the cell, range of cells, or nonadjacent selections that you want to name.
Click the Name box at the left end of the formula bar.
Type the name that you want to use to refer to your selection.
Press ENTER
 

Spooky

Registered User.
Local time
Today, 14:07
Joined
Jun 11, 2012
Messages
18
Ahh. That makes sense.

Thanks!
 

Users who are viewing this thread

Top Bottom