Issues with concatenate a Worksheet name

Merenat

New Member
Joined
Mar 15, 2023
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hello everyone,

I need to refer a worksheet to modify some properties. My problem is that the name comes from a index value.

The sheet name is Template1(1) and is the sixth sheet.
Worksheets(cell + 5).Visible = True --> works fine and do the job, but how can I call by his name? If there were changes in the number of sheets, it would surely stop working.
Worksheets(("Template" & cell)).Visible = True --> Don't work
Worksheets(""" & cell &""").Visible = True --> Don't Work either.

What would be the correct way to call him? No matter how hard I try, I don't see it.

Thank you, have a nice day.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
In the VBA you can set the Name to what you need then deal with it using that name . . .
1682520182594.png


Then you can refer to it like this ...
VBA Code:
    fileCreation = Now()
    sheetName = Format(fileCreation, "yyyymmddhhnnss") & "-" & Range("CustomerName").Value
    Template.Visible = xlSheetVisible
    Template.Copy After:=Worksheets(Worksheets.Count)
    ActiveSheet.Name = sheetName
    Template.Visible = xlSheetHidden
    Sheets(sheetName).Range("$A$1").PasteSpecial Paste:=xlPasteValues
 
Upvote 0
You can also call it via the other (Name) like my template page above. (Direct object reference)
The other Sheets(sheetName) is indirect via named sheet/index
 
Upvote 0
Thanks CSmith,
I think I have not explained well or I'm not understanding what you want to explain.

Cell is the value of the index, and changes between 1 and the last number.
The sheet tab name is 1,2,3... to match index. But if I refeer like :
Worksheets(cell).Visible = True
The changes are made in the Aux tab. I think I need to add the quotes to refer to the name in parentheses but i can't manage to add the cuotes in the code.

Nombre.jpg


Thanks for your time and patience.
 
Upvote 0
Thank you Fluff,

Works great and is elegant.

I mark it as solved.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,079
Messages
6,122,998
Members
449,092
Latest member
masterms

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