Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-09-2025, 09:05 AM
Logit Logit is offline Excel template Windows 10 Excel template Office 2007
Expert
 
Join Date: Jan 2017
Posts: 591
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default

Yes it can be done. Here is code that creates new sheets that conform to a TEMPLATE sheet located in the same workbook.

Code:
Sub MoreAndMoreSheets()

    Dim ListSh As Worksheet, BaseSh As Worksheet
    Dim NewSh As Worksheet
    Dim ListOfNames As Range, LRow As Long, Cell As Range

    With ThisWorkbook
        Set ListSh = .Sheets("List") '--Qualify our sheets.
        Set BaseSh = .Sheets("Template")
    End With

    LRow = ListSh.Cells(Rows.Count, "A").End(xlUp).Row '--Get last row of list.
    Set ListOfNames = ListSh.Range("A2:A" & LRow) '--Qualify our list.

    With Application
        .ScreenUpdating = False '--Turn off flicker.
        .Calculation = xlCalculationManual '--Turn off calculations.
    End With

    For Each Cell In ListOfNames '--For every name in list...
        BaseSh.Copy After:=Sheets(Sheets.Count) '--Copy Template sheet.
        Set NewSh = ActiveSheet '--Let's name it NewSh.
        With NewSh
            On Error GoTo messageinfo '--In case of errors.
            .Name = Cell.Value '--Set the sheet's name to that of our current name in list.
            GoTo LetUsContinue '--Skip to the LetUsContinue block.

LetUsContinue:
            On Error GoTo 0 '--Turn off error handling.
            .Range("C1") = Cell.Value '--Change C1 to the name of current sheet.
            .Calculate '--Calculate page.
            .Cells.Copy '--Change all cells...
            .Cells.PasteSpecial xlPasteValues '--... to values.
        End With
    Next Cell

    With Application
        .Calculation = xlCalculationAutomatic '--Return to automatic calculation.
        .ScreenUpdating = True '--Return to proper state.
        
    End With
Exit Sub
    

messageinfo: '--In case of duplicate names...
MsgBox ("Duplicate name exists")
Err.Clear

On Error GoTo 0
End Sub
The MAIN worksheet has a list of SHEET NAMES beginning in A1 and going down the same column. The TEMPLATE sheet is positioned as the first sheet in the workbook (not that it matters) and the MAIN sheet is in the second position.

When you run the macro it auto creates all of the sheets in the list based on the TEMPLATE sheet.



See attached.
Attached Files
File Type: xlsm Template Create Tabs.xlsm (21.3 KB, 4 views)
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting data to an excel template Stevie23 Excel Programming 3 04-05-2018 12:12 AM
Excel template excel 2013 template jassie Excel 1 03-06-2017 10:36 AM
Excel Invoice Template DMU62 Excel 19 11-02-2016 12:17 PM
Excel template Excel Default Template kneghx Excel 1 05-13-2015 09:29 AM
Excel Chart Template mdarcey Excel 0 01-26-2012 08:43 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:40 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft