Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default List Box on worksheet

Working with a List Box that is situated on a worksheet, (NOT in a Dialog or UserForm)

how do I get the entries selected when on MultiSelect?



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default List Box on worksheet

Same as when located on a Userform

Private Sub CommandButton1_Click()
With Worksheets("sheet1")
For i = 0 To .ListBox1.ListCount - 1
If .ListBox1.Selected(i) Then
sStr = sStr & .ListBox1.List(i, 0) & vbNewLine
End If
Next
End With
MsgBox sStr

End Sub


--
Regards,
Tom Ogilvy


Stuart wrote in message
...
Working with a List Box that is situated on a worksheet, (NOT in a Dialog or
UserForm)

how do I get the entries selected when on MultiSelect?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default List Box on worksheet



I just cannot get this to work, the only thing that I can do is select it
with the following line

Worksheets("jpegs").Shapes("ListBoxMain").Select

I cannot refer to it as **Worksheets("jpegs").ListBoxMain**

Tom Ogilvy wrote in message
...
Same as when located on a Userform

Private Sub CommandButton1_Click()
With Worksheets("sheet1")
For i = 0 To .ListBox1.ListCount - 1
If .ListBox1.Selected(i) Then
sStr = sStr & .ListBox1.List(i, 0) & vbNewLine
End If
Next
End With
MsgBox sStr

End Sub


--
Regards,
Tom Ogilvy


Stuart wrote in message
...
Working with a List Box that is situated on a worksheet, (NOT in a Dialog

or
UserForm)

how do I get the entries selected when on MultiSelect?




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default List Box on worksheet

Private Sub CommandButton1_Click()
Dim lbox As MSForms.ListBox
Set lbox = Worksheets("jpegs"). _
OLEObjects("ListBoxMain").Object
For i = 0 To lbox.ListCount - 1
If lbox.Selected(i) Then
sStr = sStr & lbox.List(i, 0) & vbNewLine
End If
Next

MsgBox sStr

End Sub

--
Regards,
Tom Ogilvy




Stuart wrote in message
...


I just cannot get this to work, the only thing that I can do is select it
with the following line

Worksheets("jpegs").Shapes("ListBoxMain").Select

I cannot refer to it as **Worksheets("jpegs").ListBoxMain**

Tom Ogilvy wrote in message
...
Same as when located on a Userform

Private Sub CommandButton1_Click()
With Worksheets("sheet1")
For i = 0 To .ListBox1.ListCount - 1
If .ListBox1.Selected(i) Then
sStr = sStr & .ListBox1.List(i, 0) & vbNewLine
End If
Next
End With
MsgBox sStr

End Sub


--
Regards,
Tom Ogilvy


Stuart wrote in message
...
Working with a List Box that is situated on a worksheet, (NOT in a

Dialog
or
UserForm)

how do I get the entries selected when on MultiSelect?






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default List Box on worksheet

Hi Tom,
I still can't get your code to work! I get the run time error 1004 "Unable
to get the OLEobjets properties of the worksheet class " message at the "Set
lbox" line

I messed around for ages and finally got the following to work, however, I
am sure your suggestions is the proper way to do it, and I would like to
understand where I am going wrong.

Sub GetVal()
Dim lBox, dePart1
Set lBox = Sheets("Sheet4").ListBoxes("List Box 1")
dePart1 = ""
With lBox
For i = 1 To .ListCount
If .Selected(i) Then
dePart1 = dePart1 & .List(i) & ":::"
End If
Next i
End With
Range("C1") = dePart1
End Sub



Tom Ogilvy wrote in message
...
Private Sub CommandButton1_Click()
Dim lbox As MSForms.ListBox
Set lbox = Worksheets("jpegs"). _
OLEObjects("ListBoxMain").Object
For i = 0 To lbox.ListCount - 1
If lbox.Selected(i) Then
sStr = sStr & lbox.List(i, 0) & vbNewLine
End If
Next

MsgBox sStr

End Sub

--
Regards,
Tom Ogilvy




Stuart wrote in message
...


I just cannot get this to work, the only thing that I can do is select

it
with the following line

Worksheets("jpegs").Shapes("ListBoxMain").Select

I cannot refer to it as **Worksheets("jpegs").ListBoxMain**

Tom Ogilvy wrote in message
...
Same as when located on a Userform

Private Sub CommandButton1_Click()
With Worksheets("sheet1")
For i = 0 To .ListBox1.ListCount - 1
If .ListBox1.Selected(i) Then
sStr = sStr & .ListBox1.List(i, 0) & vbNewLine
End If
Next
End With
MsgBox sStr

End Sub


--
Regards,
Tom Ogilvy


Stuart wrote in message
...
Working with a List Box that is situated on a worksheet, (NOT in a

Dialog
or
UserForm)

how do I get the entries selected when on MultiSelect?










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default List Box on worksheet

There are two different listboxes you can add to your worksheet.

One comes from the ControlToolbox toolbar (OLEObject stuff) and one comes from
the Forms toolbar (.listboxes("list box 1") stuff).

Tom's code will work for the ControlToolbox listbox.

Your code will work for the Forms toolbar listbox.



Stuart wrote:

Hi Tom,
I still can't get your code to work! I get the run time error 1004 "Unable
to get the OLEobjets properties of the worksheet class " message at the "Set
lbox" line

I messed around for ages and finally got the following to work, however, I
am sure your suggestions is the proper way to do it, and I would like to
understand where I am going wrong.

Sub GetVal()
Dim lBox, dePart1
Set lBox = Sheets("Sheet4").ListBoxes("List Box 1")
dePart1 = ""
With lBox
For i = 1 To .ListCount
If .Selected(i) Then
dePart1 = dePart1 & .List(i) & ":::"
End If
Next i
End With
Range("C1") = dePart1
End Sub

Tom Ogilvy wrote in message
...
Private Sub CommandButton1_Click()
Dim lbox As MSForms.ListBox
Set lbox = Worksheets("jpegs"). _
OLEObjects("ListBoxMain").Object
For i = 0 To lbox.ListCount - 1
If lbox.Selected(i) Then
sStr = sStr & lbox.List(i, 0) & vbNewLine
End If
Next

MsgBox sStr

End Sub

--
Regards,
Tom Ogilvy




Stuart wrote in message
...


I just cannot get this to work, the only thing that I can do is select

it
with the following line

Worksheets("jpegs").Shapes("ListBoxMain").Select

I cannot refer to it as **Worksheets("jpegs").ListBoxMain**

Tom Ogilvy wrote in message
...
Same as when located on a Userform

Private Sub CommandButton1_Click()
With Worksheets("sheet1")
For i = 0 To .ListBox1.ListCount - 1
If .ListBox1.Selected(i) Then
sStr = sStr & .ListBox1.List(i, 0) & vbNewLine
End If
Next
End With
MsgBox sStr

End Sub


--
Regards,
Tom Ogilvy


Stuart wrote in message
...
Working with a List Box that is situated on a worksheet, (NOT in a

Dialog
or
UserForm)

how do I get the entries selected when on MultiSelect?







--

Dave Peterson

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
automatically appending newly added data on worksheet to a master list worksheet tabylee via OfficeKB.com Links and Linking in Excel 0 December 17th 09 04:24 PM
Info from worksheet to worksheet pulling from list Alash25 Excel Discussion (Misc queries) 2 December 12th 08 03:35 PM
Help Creating a Drop Down List from a List in another worksheet Pat Excel Discussion (Misc queries) 1 November 25th 08 06:44 PM
How generate new list in another worksheet from existing list? NSF Excel Worksheet Functions 0 September 24th 08 01:08 PM
Trying to list tab/worksheet names in a summary worksheet Mich Excel Discussion (Misc queries) 1 February 7th 08 02:07 AM


All times are GMT +1. The time now is 12:26 PM.

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"