Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 . |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 . |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
RENAMING WORKSHEETS | Excel Worksheet Functions | |||
Worksheet Renaming | Excel Discussion (Misc queries) | |||
Worksheet Renaming | Excel Worksheet Functions | |||
renaming problem | Excel Worksheet Functions | |||
Renaming within VBA | Excel Programming |