ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Renaming Problems (https://www.excelbanter.com/excel-programming/278566-renaming-problems.html)

Matt[_17_]

Renaming Problems
 
I am trying to get a macro to copy a worksheet and
rename it sheet sequentially. The way the macro needs
to be set up is so that, every time it copies the first
sheet and renames after the last sheet

The current name format is "Sheet1(2)"

Matt

Nikos Yannacopoulos[_2_]

Renaming Problems
 
I understand you are trying to copy Sheet1 in a new sheet
in the same workbook, and what troubles you is the name of
the new sheet? For instance, if you already have 4 sheets,
you would want the new one to be named Sheet5 rather than
Sheet1(2)? Try the following after you have copied the
sheet:

shct = ActiveWorkbook.Sheets.Count
ActiveSheet.Name = "Sheet" & shct

Nikos Y.


-----Original Message-----
I am trying to get a macro to copy a worksheet and
rename it sheet sequentially. The way the macro needs
to be set up is so that, every time it copies the first
sheet and renames after the last sheet

The current name format is "Sheet1(2)"

Matt
.


Matt[_17_]

Renaming Problems
 
Thanks mate that worked and did just what I wanted.

Matt


"Nikos Yannacopoulos" wrote in message ...
I understand you are trying to copy Sheet1 in a new sheet
in the same workbook, and what troubles you is the name of
the new sheet? For instance, if you already have 4 sheets,
you would want the new one to be named Sheet5 rather than
Sheet1(2)? Try the following after you have copied the
sheet:

shct = ActiveWorkbook.Sheets.Count
ActiveSheet.Name = "Sheet" & shct

Nikos Y.


-----Original Message-----
I am trying to get a macro to copy a worksheet and
rename it sheet sequentially. The way the macro needs
to be set up is so that, every time it copies the first
sheet and renames after the last sheet

The current name format is "Sheet1(2)"

Matt
.


J.E. McGimpsey

Renaming Problems
 
Note that you'll get a run-time error with this if a sheet already
exists with that name. For instance, if you have 5 sheets to begin
with, delete Sheet2, then add a sheet, Sheets.Count will return 5
and ActiveSheet.Name = "Sheet" & shct will give an error.

You may want to prevent that with something like:

Dim shct As Integer
shct = ActiveWorkbook.Sheets.Count - 1
On Error Resume Next
Do
shct = shct + 1
ActiveSheet.Name = "Sheet" & shct
Loop Until ActiveSheet.Name = "Sheet" & shct
On Error GoTo 0




In article ,
"Nikos Yannacopoulos" wrote:

I understand you are trying to copy Sheet1 in a new sheet
in the same workbook, and what troubles you is the name of
the new sheet? For instance, if you already have 4 sheets,
you would want the new one to be named Sheet5 rather than
Sheet1(2)? Try the following after you have copied the
sheet:

shct = ActiveWorkbook.Sheets.Count
ActiveSheet.Name = "Sheet" & shct



All times are GMT +1. The time now is 10:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com