Renaming worksheet - increment by 1

B-radK

Board Regular
Joined
Apr 1, 2010
Messages
96
Office Version
  1. 365
Platform
  1. Windows
Hi team,

I have a workbook that opens another workbook, copies the cells I require, and pastes them into a new worksheet.

This is the code I have already:

Code:
Sub AddSheet()
Application.GetOpenFilename
Cells.Select
Selection.Copy
ThisWorkbook.Activate
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Week"
Cells.Select
ActiveSheet.Paste
Range("A1:I1").Select
ActiveWindow.DisplayGridlines = False
End Sub

Once this has macro has been executed, I manually rename the worksheet to say "Week 10" for example. The previous sheet names are "Week 1", "Week 2", "Week 3", etc...

Could you please help me to amend my code so it renames the tab by an increment of 1?

And could also help me to close the worksheet where I copied the data from and not save any changes to it?

Any help would be greatly appreciated.
Thanks team.

Cheers
Brad.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Maybe just add the sheets.count minus the know fixed sheets to the macro. So if you had 3 fixed sheets you'd use....

Code:
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Week " & Sheets.Count - 3
 
Upvote 0
Hi Dave and Asator,

Thank you very much for your prompt replies.
Asator, I used your code:
Code:
.Name = "Week " & Worksheets.Count + 1
I have a worksheet at the very front of the book named "Summary". When the code executes, the worksheet after worksheet "Week 10" is renamed to "Week 12", not "Week 11". This is obviously because the first sheet is "Summary" then the next sheet starts from "Week 1". Do you have any idea as to remedy this?

Thanks again for your help.
Cheers
Brad.
 
Upvote 0
Just get rid of the + 1.

I was going under the assumption that you just had sheets for the various weeks.

Sheets.Count just counts the total sheets in the book BEFORE the new one is added. If you had 3 summary sheets, you could do worksheets.count - 2. (- 3 existing + 1 new one).
 
Upvote 0
Asator,

If you're still there, do you know how to add code to the previous macro to select the worksheet name and copy it into Range("B25")?
I know how to do this using a formula, but I'm having trouble with the macro.

Thanks again mate.
Brad.
 
Upvote 0
Sorry Asator...

Once the Macro you helped me with is executed, I would like the name of the worksheet i.e. Week 12 to be copied and pasted into cell B25 of the same sheet.

Does that make sense?

Thanks again
Brad.
 
Upvote 0

Forum statistics

Threads
1,224,544
Messages
6,179,430
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top