ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Increasing the Sheet # (https://www.excelbanter.com/excel-programming/390752-increasing-sheet.html)

Please help

Increasing the Sheet #
 
Hi all,

I have an Excel sheet that links to Access database. I have created a macro
to copy the entire linked sheet and to turn the copied sheet into value.

One of my macro lines is to rename the copied sheet into "Workable Schedule
1". Here is the line:

Sheets("Linked Sheet (2)").Name = "Workable Schedule 1"

What I like to do is to make the macro to increment each copied sheet by 1
when I click on the command button on the linked sheet. For example,
"Workable Schedule 1", "Workable Schedule 2", etc.

Please help.

Thanks.

tissot.emmanuel

Increasing the Sheet #
 
Hi,

Try this:

Sub InsertRenameSheet()
Dim NewSheet As Worksheet, n As Integer
Sheets("Linked Sheet").Copy after:=Sheets(Sheets.Count)
Set NewSheet = Sheets(Sheets.Count)
n = 1
On Error Resume Next
Do
Err.Clear
NewSheet.Name = "Workable Schedule " & n
n = n + 1
Loop While Err.Number 0
On Error GoTo 0
End Sub

Note that if one of the copied sheet is deleted the number will be re-used
at the next run.

Regards,

Manu/

"Please Help" a écrit dans le message
de news: ...
Hi all,

I have an Excel sheet that links to Access database. I have created a
macro
to copy the entire linked sheet and to turn the copied sheet into value.

One of my macro lines is to rename the copied sheet into "Workable
Schedule
1". Here is the line:

Sheets("Linked Sheet (2)").Name = "Workable Schedule 1"

What I like to do is to make the macro to increment each copied sheet by 1
when I click on the command button on the linked sheet. For example,
"Workable Schedule 1", "Workable Schedule 2", etc.

Please help.

Thanks.




Please help

Increasing the Sheet #
 
Good morning Manu,

Thanks for your help. Your code works perfectly. Thanks again.

"tissot.emmanuel" wrote:

Hi,

Try this:

Sub InsertRenameSheet()
Dim NewSheet As Worksheet, n As Integer
Sheets("Linked Sheet").Copy after:=Sheets(Sheets.Count)
Set NewSheet = Sheets(Sheets.Count)
n = 1
On Error Resume Next
Do
Err.Clear
NewSheet.Name = "Workable Schedule " & n
n = n + 1
Loop While Err.Number 0
On Error GoTo 0
End Sub

Note that if one of the copied sheet is deleted the number will be re-used
at the next run.

Regards,

Manu/

"Please Help" a écrit dans le message
de news: ...
Hi all,

I have an Excel sheet that links to Access database. I have created a
macro
to copy the entire linked sheet and to turn the copied sheet into value.

One of my macro lines is to rename the copied sheet into "Workable
Schedule
1". Here is the line:

Sheets("Linked Sheet (2)").Name = "Workable Schedule 1"

What I like to do is to make the macro to increment each copied sheet by 1
when I click on the command button on the linked sheet. For example,
"Workable Schedule 1", "Workable Schedule 2", etc.

Please help.

Thanks.






All times are GMT +1. The time now is 03:37 PM.

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