ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Pass a form Listbox as an object (https://www.excelbanter.com/excel-programming/346027-pass-form-listbox-object.html)

Brian

Pass a form Listbox as an object
 
I'm trying to pass a vba forms listbox as an object.

Scenario: I have a form with two populated listboxes. When I click on one,
I want to perform an action based on the value selected. The action is
independent of which listbox is selected, but needs to know somethings about
the listbox activated.

How do I pass the listbox object as an argument?

Thanks for the help.
Brian



Bob Phillips[_6_]

Pass a form Listbox as an object
 
Brian,

This example should show you

Private Sub ListBox1_Click()
WhichListbox Me.ListBox1
End Sub

Private Sub ListBox2_Click()
WhichListbox Me.ListBox2
End Sub

Sub WhichListbox(LB As msforms.ListBox)
MsgBox LB.Name
End Sub

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Brian" wrote in message
...
I'm trying to pass a vba forms listbox as an object.

Scenario: I have a form with two populated listboxes. When I click on

one,
I want to perform an action based on the value selected. The action is
independent of which listbox is selected, but needs to know somethings

about
the listbox activated.

How do I pass the listbox object as an argument?

Thanks for the help.
Brian





Brian

Pass a form Listbox as an object
 
That was it!!!

Thanks,

Funny thing is my test code was doing just what you demonstrated...
msgbox-ing the lb name.

Anyway.... I'll remember this one.

B



"Bob Phillips" wrote in message
...
Brian,

This example should show you

Private Sub ListBox1_Click()
WhichListbox Me.ListBox1
End Sub

Private Sub ListBox2_Click()
WhichListbox Me.ListBox2
End Sub

Sub WhichListbox(LB As msforms.ListBox)
MsgBox LB.Name
End Sub

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Brian" wrote in message
...
I'm trying to pass a vba forms listbox as an object.

Scenario: I have a form with two populated listboxes. When I click on

one,
I want to perform an action based on the value selected. The action is
independent of which listbox is selected, but needs to know somethings

about
the listbox activated.

How do I pass the listbox object as an argument?

Thanks for the help.
Brian








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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com