Copy Existing Worksheet from a Listbox, then Rename

jewkes6000

Board Regular
Joined
Mar 25, 2020
Messages
55
Office Version
  1. 365
Platform
  1. Windows
I have a userform listbox which allows users to select any of the worksheets from the workbook. Then, after selecting the worksheet they want copied, I would like to change the name of that worksheet with VBA. The problem is that when the sheet gets copied, Excel automatically adds "(2)" to avoid a duplicate sheet name. There comes my issue to identify the sheet which needs to be renamed. Here is my code. The last line of code is my issue.

VBA Code:
Private Sub CommandButton_OK_Click()
   
    CopySheetName = ListBox_SheetNames.Value 'The listbox value is whichever sheet the user choose to copy from the userform'

'Creates new sheet named "New Sheet Name"
    Sheets(CopySheetName).Visible = True
    Sheets(CopySheetName).Select
    Sheets(CopySheetName).Copy After:=Sheets("Summary Sheet")
    Sheets(CopySheetName) + "(2)".Name = "New Sheet Name"

End Sub
 

Some videos you may like

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

jewkes6000

Board Regular
Joined
Mar 25, 2020
Messages
55
Office Version
  1. 365
Platform
  1. Windows
I answered my own question using Concatenate in VBA. The last line of code should like this:
Sheets(CopySheetName & " (2)").Name = "New Sheet Name"

Be sure to put a space between the " and the "(2).
 

Watch MrExcel Video

Forum statistics

Threads
1,127,893
Messages
5,627,491
Members
416,250
Latest member
darius_rebelo

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
Top