same macro for Different ListBoxes

drom

Well-known Member
Joined
Mar 20, 2005
Messages
543
Office Version
  1. 2021
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 2007
Hi and Thanks in Advance

I have 4 different Active X Controls, ListBoxes whithin my WorkBook with "multiselect=fmMultiSelectMulti"


I have to use 3 different macros doing many different jobs with this ListBoxes.
But the Jobs are the same for this 4 ListBoxes.

So I would like to use a generic macro.

Code:
If Sheet2.ListBox1.Selected(1) = True Then MsgBox "Thanks 1"
If Sheet3.ListBox2.Selected(1) = True Then MsgBox "Thanks 2"
If Sheet45.ListBox3.Selected(1) = True Then MsgBox "Thanks 3"

is there a way to refer to this ListBoxes like:

If Sheets(Sheet2.Name).ListBoxes("ListBox1").Selected(1) = True Then MsgBox "Thanks 1"


I mean use generic names to be able to use just 3 macros and not (4*3=12) macros
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
SOLVED: same macro for Different ListBoxes

Code:
Sub Macro1(LBox As MSForms.ListBox)' does the job
 'CODE
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,502
Messages
6,179,126
Members
452,890
Latest member
Nikhil Ramesh

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