+ Reply to Thread
Results 1 to 3 of 3

Create a new sheet based on a Cells value

Hybrid View

  1. #1
    Registered User
    Join Date
    02-04-2010
    Location
    North Carolina
    MS-Off Ver
    Excel 2007
    Posts
    52

    Create a new sheet based on a Cells value

    Hey all,
    I have a main sheet with personnel and some data. Each person should get a separate sheet name ex: "Kent, Clark" on main sheet should have a sheet named "Kent-Log" in the same workbook.
    I have a template setup already for Kent. What I am looking to do is when I enter a new persons name(Last, First) on the main sheet, i want VBA to copy "Kent-Log" and rename to "Last-Log". I have several people to add and am trying to avoid -copy ->move to end--> rename

    Any help is greatly appreciated.
    Last edited by usafmeinweg; 04-05-2010 at 09:44 AM.

  2. #2
    Valued Forum Contributor mdbct's Avatar
    Join Date
    11-11-2005
    Location
    CT
    MS-Off Ver
    2003 & 2007
    Posts
    848

    Re: Create a new sheet based on a Cells value

    The following will create a new sheet for every entry in column A from row 2 on down on a sheet called Main. If the sheet already exists, the name will be skipped.

    Sub addSheets()
        Dim strName As String, strNew As String
        Dim sMain As Worksheet
        Set sMain = Sheets("Main")
        Dim i As Long
        i = 2
        Do Until sMain.Cells(i, 1) = ""
            On Error Resume Next
            strName = sMain.Cells(i, 1)
            strNew = Left(strName, InStr(strName, ",") - 1) & "-" & "Log"
            If Not Sheets(strNew).Index > 0 Then
                Sheets("Kent-Log").Copy after:=Sheets(Sheets.Count)
                ActiveSheet.Name = strNew
            Else
                'do nothing
            End If
            Err.Clear
            i = i + 1
        Loop
    End Sub

  3. #3
    Registered User
    Join Date
    02-04-2010
    Location
    North Carolina
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Create a new sheet based on a Cells value

    Thanks. Worked like a charm

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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