determine list index numbers in a multiselect listbox vba

I have a single column, multi-select, ActiveX Listbox control in an Excel 2010 spreadsheet named "Docks".
I want to determine all of the row numbers selected by the user and put those numbers in a column on Sheet1, beginning at W43.  
What I've found in searching are ways to place the listbox values but not the row index numbers.
jthomp222Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
Dim lngIndex As Long
Dim lngRow As Long

lngRow = 43
For lngIndex = 0 To ListBox1.ListCount - 1
    If ListBox1.Selected(lngIndex) Then
        Cells(lngRow, "W") = lngIndex
        lngRow = lngRow + 1
    End If
Next

Open in new window

[ fanpages ]IT Services ConsultantCommented:
The following code clears the contents of cell [W43] of the [Sheet1] worksheet to the extent of the data in that column, then loops through the Listbox control (named "ListBox1") on the [Docks] worksheet checking for Selected items.

The ListIndex numbers of the Selected items are placed within column [W] of the [Sheet1] worksheet, starting at row 43.
  Dim lngLoop                                           As Long
  Dim lngRow                                            As Long
  
  lngRow = Worksheets("Sheet1").Cells(Worksheets("Sheet1").Rows.Count, "W").End(xlUp)
  
  If lngRow >= 43& Then
     Worksheets("Sheet1").Range(Worksheets("Sheet1").Cells(43&, "W"), lngRow).ClearContents
  End If
  
  lngRow = 43&
  
  For lngLoop = 0& To (Worksheets("Docks").ListBox1.ListCount - 1&)
      If (Worksheets("Docks").ListBox1.Selected(lngLoop)) Then
         Worksheets("Sheet1").Cells(lngRow, "W") = lngLoop
         lngRow = lngRow + 1&
      End If
  Next lngLoop

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jthomp222Author Commented:
Thanks, Fanpages.  I apologize for my not clarifying in my question that it is the ListBox that is nam3ed "Docks", not the spreadsheet.

Can I simply remove:
(Worksheets("Docks").
from line 12?
[ fanpages ]IT Services ConsultantCommented:
:)

Yes, as long as you change the references to ListBox1 to Docks.

Thanks for closing the question so promptly in any respect.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.