VBA: Duplicate a sheet and give it a name based on a standard value and a variant

2_nisia

New Member
Joined
Sep 26, 2022
Messages
18
Platform
  1. Windows
Hey everyone,

I have the following code:


...

If IsEmpty(Sheets("Start").Cells(number, 7).Value) Then
s = InputBox("How would you like to call it?")
If s = "" Then Exit Sub 'Sub gets exited if no sheet name entered or "Cancel" clicked

ActiveWorkbook.Sheets(Tax(Choice)).Visible = True 'Makes hidden sheet visible
Sheets(Tax(Choice)).Copy , Sheets(Sheets.Count) 'Copies the sheet now visible sheet and inserts at the end of all sheets
ActiveWorkbook.Sheets(Tax(Choice)).Visible = False 'Makes sheet hidden again'



With ActiveSheet.Name = Sheets("Tax_" + s)
MsgBox "The tax sheet is now created"

End With

...

I want to keep that Tax_ name and add the choice of the user next to it. So if the user chooses to name it house, I want the duplicated sheet to be named Tax_house

I have found threads on how to name sheets based on a standard value, or based on an activesheet name, but none that show how to combine both.

Hope you understand my question and thanks in advance!
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi *2_nisia and Welcome to the Board! I think you can just use this code to name the sheet. HTH. Dave
Code:
ActiveSheet.Name = "Tax_" & s
ps. Please use code tags
 
Upvote 0
Hi & Welcome to MrExcel.
How about
VBA Code:
If IsEmpty(Sheets("Start").Cells(Number, 7).Value) Then
   s = InputBox("How would you like to call it?")
   If s = "" Then Exit Sub 'Sub gets exited if no sheet name entered or "Cancel" clicked

   ActiveWorkbook.Sheets(Tax(Choice)).Visible = True 'Makes hidden sheet visible
   Sheets(Tax(Choice)).Copy , Sheets(Sheets.Count) 'Copies the sheet now visible sheet and inserts at the end of all sheets
   ActiveSheet.Name = "Tax_" & s
   
   ActiveWorkbook.Sheets(Tax(Choice)).Visible = False 'Makes sheet hidden again'
   MsgBox "The tax sheet is now created"
End If
 
Upvote 0
Solution
Hi & Welcome to MrExcel.
How about
VBA Code:
If IsEmpty(Sheets("Start").Cells(Number, 7).Value) Then
   s = InputBox("How would you like to call it?")
   If s = "" Then Exit Sub 'Sub gets exited if no sheet name entered or "Cancel" clicked

   ActiveWorkbook.Sheets(Tax(Choice)).Visible = True 'Makes hidden sheet visible
   Sheets(Tax(Choice)).Copy , Sheets(Sheets.Count) 'Copies the sheet now visible sheet and inserts at the end of all sheets
   ActiveSheet.Name = "Tax_" & s
  
   ActiveWorkbook.Sheets(Tax(Choice)).Visible = False 'Makes sheet hidden again'
   MsgBox "The tax sheet is now created"
End If
Thanks a lot! That did the trick!! :D
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,829
Messages
6,181,222
Members
453,024
Latest member
Wingit77

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