Excel/Copy hidden sheet & rename
I’m not sure if this can be done, but this is what I would like to do in VBA.
I am going to have several worksheets, the first one holds some source data that the others feed from, it is called “NAMES” and is the first sheet (always to the left).
The other sheet/s are called “Country 1”, “Country 2”…….“Country 18” and so on and these are going to be added as needed, so what I am wanting to do is have a hidden sheet (so it cannot be seen or altered) that is formatted how I want with formulas etc, have it named say “Spare” and then when a new sheet needs to be added the “Spare sheet can be copied and given a new name. The new name would be the highest “Country” so if “Country 5” was the current highest sheet the newly copied “Spare” sheet would be then called “Country 6” this would be then placed just after the “NAMES” sheet or the 2nd sheet from the left.
I hope this can be achieved and if you need any further information that I may have omitted please let me know.
Thanks you very much for your assistance.
Here is some starter code:
Dim sh1 As Worksheet
Dim s As String, l As Long, maxval As Long, sname As String
Dim sh As Worksheet
Set sh = Worksheets("Spare")
sh.Visible = xlSheetVisible
Set sh1 = ActiveSheet
sh.Visible = xlSheetHidden
maxval = 0
For Each sh In Worksheets
If sh.Visible Then
sname = sh.Name
If InStr(1, sname, "country", vbTextCompare) Then
s = Mid(sname, 9, 2)
l = CLng(s)
If maxval < l Then maxval = l
sh1.Name = "Country " & maxval + 1
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here