VBA duplicate Workbook with sheet names from list

MacroNobie

New Member
Joined
Mar 29, 2018
Messages
12
Hi everybody, I am working on a dashboard, I have a finished one for a specific region and know I want to replicate that workbook but have the sheet name with the region changed so for example this workbook has: Directory, Region 1, Data. I would like to copy it and have: Directory, Region 2, Data.

Is there a way? Thanks for the help!!
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Code:
Public Sub SaveAsNewRegion()
Dim vNum, vName
Dim sht As Worksheet


vNum = InputBox("Enter Region#", "Save As New Region Workbook")
If vNum = "" Then Exit Sub


For Each sht In Worksheets
  If InStr(sht.Name, "Region") > 0 Then
     vName = "Region " & vNum
     sht.Name = vName
     ActiveWorkbook.SaveAs "Workbook_" & vName & ".xlsx"
     Exit Sub
  End If
Next
End Sub
 
Upvote 0
Another option
Code:
Sub NewWbk()

   Dim Ws As Worksheet
   Dim Fname As String
   For Each Ws In Worksheets
      If Ws.Name Like "Region*" Then
         Ws.Name = "Region " & Right(Ws.Name, 1) + 1
         Fname = Ws.Name
         Exit For
      End If
   Next Ws
   ActiveWorkbook.SaveAs ActiveWorkbook.Path & "\" & Fname, 52
End Sub
 
Upvote 0
Thanks guys for your help. If I do this, it changes the background color, is there a way to prevent that?
 
Upvote 0
Neither code change any colours.
What do you mean by background colour? & how does it change?
 
Upvote 0
It is normally a light blue but changes to light green kind of. The blue that I used it not a standard blue.
 
Upvote 0
If you are using non standard colours, then you will probably have to reset those colours in the new book. But that is something I know nothing about.
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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