ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Rename of sheets by macro (https://www.excelbanter.com/excel-discussion-misc-queries/206587-rename-sheets-macro.html)

Harshad[_2_]

Rename of sheets by macro
 
i have Sheet1 to Sheet 55 in my workbook.

I want Sheet1 rename as Main, sheet2 as Content, sheet3 as Micro, sheet4 as
Help, sheet5 as NN1, sheet6 to sheet55 as NN2 to NN50.

Sugest macro.

Thanks

Don Guillett

Rename of sheets by macro
 
Try this

Sub renamesheets()
Sheets("sheet1").Name = "Main"
'etc

For i = 5 To Sheets.Count
'Help, sheet5 as NN1, sheet6 to sheet55 as NN2 to NN50.
Sheets("sheet" & i).Name = "NN" & i - 4
Next i
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Harshad" wrote in message
...
i have Sheet1 to Sheet 55 in my workbook.

I want Sheet1 rename as Main, sheet2 as Content, sheet3 as Micro, sheet4
as
Help, sheet5 as NN1, sheet6 to sheet55 as NN2 to NN50.

Sugest macro.

Thanks



Mike H

Rename of sheets by macro
 
Why not do it all in one go when you add them

Sub Sheet_addition()
Dim i As Long
On Error GoTo endit
Application.ScreenUpdating = False
For i = 1 To 52
Sheets.Add after:=Sheets(i)
If i 1 Then ActiveSheet.Name = "NN" & i - 1
Next i
endit:
Sheets("Sheet1").Name = "Main"
Sheets("Sheet2").Name = "Content"
Sheets("Sheet3").Name = "Micro"
Sheets("Sheet4").Name = "Help"
Application.ScreenUpdating = True
End Sub

Mike

"Harshad" wrote:

i have Sheet1 to Sheet 55 in my workbook.

I want Sheet1 rename as Main, sheet2 as Content, sheet3 as Micro, sheet4 as
Help, sheet5 as NN1, sheet6 to sheet55 as NN2 to NN50.

Sugest macro.

Thanks


Harshad[_2_]

Rename of sheets by macro
 
Dear Mike & Don,

Don,
Your macro works very fine. Thank you.

Mike,
It's very nice that i can utilize both macro in a single code. It also works
very fine, but again the problem of sheet order is there.
I want it as order : Main, Content, Micro, Help, NN1, NN2.......NN51.

But it shows the order: Main, Help, NN1, NN2,...,NN51, Content, Micro.

Kindly revert back.


"Mike H" wrote:

Why not do it all in one go when you add them

Sub Sheet_addition()
Dim i As Long
On Error GoTo endit
Application.ScreenUpdating = False
For i = 1 To 52
Sheets.Add after:=Sheets(i)
If i 1 Then ActiveSheet.Name = "NN" & i - 1
Next i
endit:
Sheets("Sheet1").Name = "Main"
Sheets("Sheet2").Name = "Content"
Sheets("Sheet3").Name = "Micro"
Sheets("Sheet4").Name = "Help"
Application.ScreenUpdating = True
End Sub

Mike

"Harshad" wrote:

i have Sheet1 to Sheet 55 in my workbook.

I want Sheet1 rename as Main, sheet2 as Content, sheet3 as Micro, sheet4 as
Help, sheet5 as NN1, sheet6 to sheet55 as NN2 to NN50.

Sugest macro.

Thanks


Don Guillett

Rename of sheets by macro
 
Glad to help

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Harshad" wrote in message
...
Dear Mike & Don,

Don,
Your macro works very fine. Thank you.

Mike,
It's very nice that i can utilize both macro in a single code. It also
works
very fine, but again the problem of sheet order is there.
I want it as order : Main, Content, Micro, Help, NN1, NN2.......NN51.

But it shows the order: Main, Help, NN1, NN2,...,NN51, Content, Micro.

Kindly revert back.


"Mike H" wrote:

Why not do it all in one go when you add them

Sub Sheet_addition()
Dim i As Long
On Error GoTo endit
Application.ScreenUpdating = False
For i = 1 To 52
Sheets.Add after:=Sheets(i)
If i 1 Then ActiveSheet.Name = "NN" & i - 1
Next i
endit:
Sheets("Sheet1").Name = "Main"
Sheets("Sheet2").Name = "Content"
Sheets("Sheet3").Name = "Micro"
Sheets("Sheet4").Name = "Help"
Application.ScreenUpdating = True
End Sub

Mike

"Harshad" wrote:

i have Sheet1 to Sheet 55 in my workbook.

I want Sheet1 rename as Main, sheet2 as Content, sheet3 as Micro,
sheet4 as
Help, sheet5 as NN1, sheet6 to sheet55 as NN2 to NN50.

Sugest macro.

Thanks




All times are GMT +1. The time now is 05:02 AM.

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