Copy Existing Worksheet from a Listbox, then Rename

jewkes6000

Board Regular
Joined
Mar 25, 2020
Messages
60
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
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
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).
 
Upvote 0

Forum statistics

Threads
1,215,045
Messages
6,122,840
Members
449,096
Latest member
Erald

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