VBA to select named sheets and copy with new name

Dunk4Divin

New Member
Joined
Aug 21, 2019
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hi I am trying to select named sheets with a variable issue level the variable comes from a cell in each sheet.

Currently I have 5 sheets (could be any number) which all have the same name and issue level but are sheet numbered 1 to 5. The code should look for sheets with the sheet name and the current issue level which is taken from a cell in each sheet, then copy and rename with the next issue number. The new name and page number and issue level for the copy sheet all come from another cell in each sheet.

I have written the following code and tried a number of variations with varying levels of success but at the moment it is not doing anything! I think the way I am defining the name the sheets to look for is failing?

Sub UpIssueAllGRnR()

'Start loop to find named sheets

Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets


'Define name for sheets to be duplicated (name start and current issue number)

If Left(ws.Name, 20) = "Gauge RnR Att Iss " & Cells(4, 16) Then

'Copy active sheet

ActiveSheet.Copy After:=Sheets(ActiveSheet.Index)

'Rename new sheet from defined cell (Same name and sheet number but with new issue level)

Dim NewNamex As String
NewNamex = ActiveSheet.Range("P14").Value
ActiveSheet.Name = NewNamex
End If
'Go to next defined sheet name

Next ws

End Sub


Any help would be greatly appreciated
 

Attachments

  • ScreenPrint.gif
    ScreenPrint.gif
    204.8 KB · Views: 10

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,214,826
Messages
6,121,795
Members
449,048
Latest member
greyangel23

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