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

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
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,531
Messages
6,179,380
Members
452,907
Latest member
Roland Deschain

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