Select Case Sh.Name

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,124
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I'm working with an xlsm parent document where the sheet's tab names changes in producing a new children workbook.

My question is is there a way to generically assign a sheet name according to its assigned worksheet#/sheet# in the code below, so I can avoid using over a hundred sheet names in the parent document?



Code:
  Sub Workbook_SheetTabName
    Select Case Sh.Name
    Case "Month001": Call Refresh1
    Case "Month002": Call Refresh2

'so on until ...

    Case "Month099": Call Refresh1
    Case "Month100": Call Refresh2
    Case Else: Call Refresh4
    End Select
    
    
End Sub


Please let me know, if you should need an example/further explanation.

Thank you!

Pinaceous
 
Last edited:

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
Is it straight on like you show it? In other words, is it basically that odd number sheet names call Refresh1 and even number sheet names call Refresh2? If so there may be another way. I'd have to try it out tomorrow at work.
 
Upvote 0
Hi jproffer,

Here's another look at the code in a different way that might help explain this situation that I'm trying to accomplish:

Code:
Option Explicit
Sub Workbook_SheetActivate_MonthlyReport(ByVal Sh As Object)-?
    Select Case Sh.Name
    Case "Sheet1": Call October_MTHLYReport
    Case "Sheet5": Call November_MTHLYReport
    Case "Sheet7": Call December_MTHLYReport
    Case "Sheet9": Call January_MTHLYReport
    Case "Sheet11": Call February_MTHLYReport
    Case "Sheet13": Call March_MTHLYReport
    Case "Sheet15": Call April_MTHLYReport
    Case "Sheet17": Call May_MTHLYReport
    Case "Sheet19": Call June_MTHLYReport
    Case "Sheet21": Call July_MTHLYReport
    Case "Sheet23": Call August_MTHLYReport
    Case "Sheet25": Call September_MTHLYReport
    End Select
End Sub

Whereby, I'm in the code, I'm trying to avoid the using the actual "Sheet Name", so I can substitute its actual "Sheet Name" with its generic "Sheet Number".

So, if the "Sheet Name" changes, the code will know what to execute based on its "Sheet Number".

Is this possible? XL always surprises me.

Many thanks,
Paul
 
Upvote 0
So you have one call per month.
So why would you have more then 100?
You said:
so I can avoid using over a hundred sheet names in the parent document?
 
Upvote 0
I'm also experimenting with this code:

Code:
Option Explicit
Sub Workbook_SheetActivate_MonthlyReport()
 Select Case True
    
    Case Worksheets(4): Call October_MTHLYReport
    Case Worksheets(6): Call November_MTHLYReport
    Case Worksheets(8): Call December_MTHLYReport
    Case Worksheets(10): Call January_MTHLYReport
    Case Worksheets(12): Call February_MTHLYReport
    Case Worksheets(14): Call March_MTHLYReport
    Case Worksheets(16): Call April_MTHLYReport
    Case Worksheets(18): Call May_MTHLYReport
    Case Worksheets(20): Call June_MTHLYReport
    Case Worksheets(22): Call July_MTHLYReport
    Case Worksheets(24): Call August_MTHLYReport
    Case Worksheets(26): Call September_MTHLYReport
    End Select
End Sub

Whereby, here in the code, I'm trying to avoid the using the actual "Sheet Name", so I'm substituting its actual "Sheet Name" with its generic "Worksheet Number".

Same ides, where, if the "Sheet Name" changes, the code will know what to execute based on its "Worksheet Number".
 
Upvote 0
So you have one call per month.
So why would you have more then 100?
You said:
so I can avoid using over a hundred sheet names in the parent document?


Because the parent document has many sheet names in designating its children.

So, the sheet name for each child's can be:

________________________
AA October ... AA September

... so on ...

AZ October ... AZ September
________________________

... so on ...
________________________
BA October ... BA September

... so on ...

BZ October ... BZ September
_______________________


& so on.

This part is not important. The idea avoid the using the actual "Sheet Name", with a generic "Sheet Number" or a "Worksheet Number" is.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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