Worksheet names

John

New Member
Joined
Mar 12, 2002
Messages
24
Can any one please help me with some vba code that will identify the names of the worksheets in a workbook and then assign a different macro to each one. There are a number of sheets that are hidden and when the work book is used only those that are required are "unhidden" It is to these sheets that I want to assign macros.

Thanks
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
On 2002-03-21 20:30, John wrote:
Can any one please help me with some vba code that will identify the names of the worksheets in a workbook and then assign a different macro to each one. There are a number of sheets that are hidden and when the work book is used only those that are required are "unhidden" It is to these sheets that I want to assign macros.

Thanks

To get Sheet Names;
Sub sheetNames()
Dim Sh As Worksheet
Dim i As Integer

For Each Sh In ThisWorkbook.Sheets
Cells(i + 1, 1) = Sh.Name
i = i + 1
Next
End Sub


Unsure about what you mean about assign macros to these sheets ??


Ivan
 
Upvote 0
Thanks Ivan.

I want to call or run a macro. Since each sheet has different data on it I need to use the name of the sheet to call the macro.
for example if the sheet name is data one I want to call Data_1

Regards
 
Upvote 0
Hi! Do you mean something like this?
Please execute "Test".

Sub Test()
Dim sh As Worksheet
For Each sh In Worksheets
If sh.Visible = xlSheetVisible Then
Application.Run ThisWorkbook.Name & "!" & sh.Name
End If
Next
End Sub

Sub Data_1()
MsgBox "Data_1 has been executed"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,516
Messages
6,119,981
Members
448,934
Latest member
audette89

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