+ Reply to Thread
Results 1 to 3 of 3

Function for sheets

Hybrid View

  1. #1
    Registered User
    Join Date
    04-25-2017
    Location
    Sweden
    MS-Off Ver
    Microsoft Office 365 ProPlus Version 2002
    Posts
    33

    Function for sheets

    Hello,

    See attached for an illustrative example of what I want to do.

    So I have this excel where I copy in a list of names. The number of names varies every time and is between 1-10 names.

    After I copy in the list of names in the Dashboard I have to create a copy of the "Template" sheet for every name and rename that specific sheet with the specific name.

    In my excel I have a list of 5 names. Is it possible somehow to automate this process? In other words, after I have copied in the list of names in the dashboard that automatically 5 sheets are made with the same formulas as the "Template" tab that are renamed with the names in the list?

    Kind Regards,

    Peter
    Attached Files Attached Files

  2. #2
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,765

    Re: Function for sheets

    Use this VBA code:

    Sub CopyAndRename()
    Dim cell As Range
    Dim lastR As Integer
    Application.ScreenUpdating = False
    lastR = Sheets("Dashboard").Cells(Rows.Count, "A").End(xlUp).Row
    For Each cell In Sheets("Dashboard").Range("A2:A" & lastR)
        Sheets("Template").Copy After:=Sheets(Worksheets.Count)
        Sheets("Template (2)").Name = Trim(cell.Value)
    Next cell
    Sheets("Dashboard").Select
    Application.ScreenUpdating = True
    End Sub
    after pasting/input name in col. A on Dashboard, run this macro.

    p.s. there is no check that particular sheet exist or not, so in case if sheet NAME1 exist and you put the same name again it gives error.
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  3. #3
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Function for sheets

    Hi there,

    Take a look at the attached version of your workbook and see if it does what you need. It uses the following code:

    
    
    
    Option Explicit
    
    
    Sub CreateWorksheets()
    
        Const sDASHBOARD    As String = "Dashboard"
        Const sTEMPLATE     As String = "Template"
        Const sNAMES        As String = "ptrNames"
    
        Dim wksDashboard    As Worksheet
        Dim wksTemplate     As Worksheet
        Dim rNames          As Range
        Dim wksNew          As Worksheet
        Dim sName           As String
        Dim rCell           As Range
        Dim wks             As Worksheet
    
        Set wksDashboard = ThisWorkbook.Worksheets(sDASHBOARD)
        Set wksTemplate = ThisWorkbook.Worksheets(sTEMPLATE)
    
        Set rNames = wksDashboard.Range(sNAMES)
    
        For Each rCell In rNames
    
            If rCell.Value <> vbNullString Then
    
                sName = rCell.Value
    
                On Error Resume Next
                    Set wks = ThisWorkbook.Worksheets(sName)
                On Error GoTo 0
    
                If wks Is Nothing Then
    
                      wksTemplate.Copy Before:=wksTemplate
    
                      Set wksNew = ActiveSheet
                          wksNew.Name = sName
    
                Else: MsgBox "This workbook already contains a worksheet called """ & sName & _
                              vbLf & vbLf & _
                             "Delete this worksheet before running this routine", vbExclamation
    
                      Exit Sub
    
                End If
    
            End If
    
        Next rCell
    
        wksDashboard.Activate
    
    End Sub
    The highlighted values may be altered to suit your requirements.

    You may enter up to ten names in the green cells on the "Dashboard" worksheet.

    Hope this helps - please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. COUNTUNIQUE Function in Google Sheets; Excel lacks a direct counterpart to this function?
    By PivotTablePSHomage in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-18-2018, 05:27 AM
  2. [SOLVED] Max Function across four sheets
    By Rookie2016 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-30-2018, 09:21 PM
  3. Address function with Sum Sheets function
    By nathan68 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-25-2016, 03:09 PM
  4. [SOLVED] Using a nested IF Function and AND function on 2 sheets?
    By heresteve2 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 04-29-2014, 02:14 PM
  5. Replies: 13
    Last Post: 04-08-2014, 05:46 AM
  6. [SOLVED] IF Function referencing IsNumber, Match, Left function on separate sheets
    By Touch9713 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-12-2013, 10:09 PM
  7. Replies: 1
    Last Post: 09-24-2011, 01:46 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1