Run a macro on selected sheets in a workbook

brianfosterblack

Active Member
Joined
Nov 1, 2011
Messages
251
I am using a listbox in a userform to select multiple client sheets. These are output to ("Other!AW:AW").
I need help with a macro which will take me to each of these sheets in turn and run a macro
I have a macro that runs on all my worksheets in a workbook but cannot seem to find one for this requirement
Can someone please help.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
I need help with a macro which will take me to each of these sheets in turn and run a macro

See if this is what you had in mind:-
(if the code is not sitting in the UserForm module you will need to replace "Me" with the form name)

VBA Code:
Sub ListBoxMultiSelect()

    Dim i As Long

    For i = 0 To Me.ListBoxName.ListCount - 1
        If Me.ListBoxName.Selected(i) Then
          Worksheets(Me.ListBoxName.List(i)).Select
          Call Macro_You_Want_To_rRun
        End If
    Next i

End Sub
 
Upvote 0
See if this is what you had in mind:-
(if the code is not sitting in the UserForm module you will need to replace "Me" with the form name)

VBA Code:
Sub ListBoxMultiSelect()

    Dim i As Long

    For i = 0 To Me.ListBoxName.ListCount - 1
        If Me.ListBoxName.Selected(i) Then
          Worksheets(Me.ListBoxName.List(i)).Select
          Call Macro_You_Want_To_rRun
        End If
    Next i

End Sub
[
[QUOTE="Alex Blakenburg, post: 5752766, member: 473943"]
See if this is what you had in mind:-
(if the code is not sitting in the UserForm module you will need to replace "Me" with the form name)

[CODE=vba]
Sub ListBoxMultiSelect()

    Dim i As Long

    For i = 0 To Me.ListBoxName.ListCount - 1
        If Me.ListBoxName.Selected(i) Then
          Worksheets(Me.ListBoxName.List(i)).Select
          Call Macro_You_Want_To_rRun
        End If
    Next i

End Sub
Hi Alex, this is not working for me. I have already extracted the items selected in the listbox and put it in a sheet ("Other") in a range named) ClientNamesSelected. I do not want to run the macro straight from the userform as I have other criteria also to take into account when running my macro and I still have to record these.
[/QUOTE]
 
Upvote 0
Hi Alex, this is not working for me. I have already extracted the items selected in the listbox and put it in a sheet ("Other") in a range named) ClientNamesSelected. I do not want to run the macro straight from the userform as I have other criteria also to take into account when running my macro and I still have to record these.
[/QUOTE]
Hi Alex, I found my problem. I had unloaded the userform instead of hiding it
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,539
Members
449,088
Latest member
RandomExceller01

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