Name newly created workbook after text string and cell ref

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,592
Office Version
  1. 365
Platform
  1. Windows
Hi all

I have this code that copies a 'Template' worksheet x number of times into a new Workbook

Code:
Dim wb As Workbook, sh1 As Worksheet
    Set sh1 = ThisWorkbook.Sheets("Info")
    ThisWorkbook.Sheets("Template").Copy
    Set wb = ActiveWorkbook
    For i = 2 To 32
        Set sh2 = wb.Sheets(i - 1)
        sh2.Name = sh1.Range("O" & i).Value
        sh2.Range("F4") = sh1.Range("K" & i).Value
        sh2.Range("E31") = sh1.Range("L" & i).Value
        sh2.Range("J31") = sh1.Range("L" & i).Value
        If wb.Sheets.Count < 31 Then
            ThisWorkbook.Sheets("Template").Copy After:=wb.Sheets(wb.Sheets.Count)
        End If
    Next

Can anybody help to change the code so that the newly created workbook is automatically named Monthly Report plus the text string found in source workbook, info sheet Range G2.

So if the source workbook, Info Sheet cell G2 holds Dec-15 the newly created workbook will be named Monthly Report Dec-15

many thanks
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
..after a few hours searching around Google I found that by adding this bit of code on the end it now works !!

Code:
End If
    Next
    're-name new workbook
    Dim sFile As String
    sFile = "Monthly Report " & [info!G2].Text & ".xlsm"
    ActiveWorkbook.SaveAs Filename:="C:\users\James\desktop\" & sFile, FileFormat:=52
 
Upvote 0

Forum statistics

Threads
1,203,469
Messages
6,055,601
Members
444,802
Latest member
lolica12

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