VBA to change name of spreadsheet via a message box

ariel20029

Board Regular
Joined
Jun 20, 2013
Messages
97
Hi, I only have very limited VBA knowledge. Can you please look at the information I have and advise me. I am trying to have excel change the name of a spreadsheet via a messagebox. I copied the below in a module. The spreadsheet I am trying to rename is Template.

thanks so much.
Sharon

Sheets ("Template")
Sheets(Sheets.Count).Name = InputBox("Copy and Paste file ID")
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Sheets(Sheets.Count).Name = InputBox("Copy and Paste file ID")

If you want your worksheet named the same as the file name you copy and paste, it should work. It is just as easy to try the code as to ask us. But in any case, you would need a procedure title line, and an end line, eg.

Code:
Sub sometingorother()
'code here
End Sub
 
Last edited:
Upvote 0
If you want your worksheet named the same as the file name you copy and paste, it should work. It is just as easy to try the code as to ask us. But in any case, you would need a procedure title line, and an end line, eg.

Code:
Sub sometingorother()
'code here
End Sub

Hi,
Thank you- next problem
Im looking to name the sheet the data that's in Cell E2
Im getting an error message at this point:
Sheets(ActiveSheet.Name) = Range("E2").Select


Any suggestions?

Full Macro below



' Macro1 Macro
Sheets("TEMPLATE").Select
Columns("D:D").Select
Selection.Copy
Columns("E:E").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("J1").Select
Application.CutCopyMode = False
Selection.Copy
Range("E1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False

Sheets(ActiveSheet.Name) = Range("E2").Select
'Sheets(ActiveSheet.Name) = InputBox("Copy and Paste file ID")
ActiveWorkbook.Save
End Sub
 
Upvote 0
Hi,
Thank you- next problem
Im looking to name the sheet the data that's in Cell E2
Im getting an error message at this point:
Sheets(ActiveSheet.Name) = Range("E2").Select


Any suggestions?

Full Macro below



' Macro1 Macro
Sheets("TEMPLATE").Select
Columns("D:D").Select
Selection.Copy
Columns("E:E").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("J1").Select
Application.CutCopyMode = False
Selection.Copy
Range("E1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False

Sheets(ActiveSheet.Name) = Range("E2").Select
'Sheets(ActiveSheet.Name) = InputBox("Copy and Paste file ID")
ActiveWorkbook.Save
End Sub

Code:
[COLOR=#0000CD]Sheets(ActiveSheet.Name) = Range("E2").Value[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,216,104
Messages
6,128,856
Members
449,472
Latest member
ebc9

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