+ Reply to Thread
Results 1 to 3 of 3

VBA: Populate a cell with newly created tab

  1. #1
    Registered User
    Join Date
    06-20-2014
    Location
    Dallas, TX
    MS-Off Ver
    2010
    Posts
    2

    VBA: Populate a cell with newly created tab

    Hi everyone! First time posting here.

    I found a VBA script on here that allowed me to copy a Template tab that I have and rename it to whatever I want.

    I wanted to take it a step further and add that same name to the next row in my Summary tab.

    Below is the VBA. Could someone help with adding the additional code to pull in the new tab name?

    Sub NewSite2()
    Dim wb As Workbook: Set wb = ThisWorkbook
    Dim ws As Worksheet: Set ws = wb.Sheets("Template")
    Dim newws As Worksheet, sh As Worksheet, newname
    Dim query As Long, xst As Boolean, info As String

    retry:
    xst = False
    newname = Application.InputBox("Enter a new sheet name.", info, , , , , , 2)
    If newname = "False" Then Exit Sub
    For Each sh In wb.Sheets
    If sh.Name = newname Then
    xst = True: Exit For
    End If
    Next
    If Len(newname) = 0 Or xst = True Then
    info = "Sheet name is invalid. Please retry."
    GoTo retry
    End If
    ws.Copy after:=ws: Set newws = ActiveSheet: newws.Name = newname
    End Sub

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: VBA: Populate a cell with newly created tab

    Hi, please use code tag (# button) around your code.

    Assuming name in Column A. Try, something like below.
    Please Login or Register  to view this content.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Registered User
    Join Date
    06-20-2014
    Location
    Dallas, TX
    MS-Off Ver
    2010
    Posts
    2

    Re: VBA: Populate a cell with newly created tab

    Thanks! This works!

+ 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. Macro to Move Files from a Folder to Newly created folders based on value in a cell
    By acsishere in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-08-2015, 08:04 PM
  2. [SOLVED] splitting multi-line cell into newly created rows
    By tranzsport in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-16-2015, 02:44 AM
  3. Auto populate master sheet with value from newly created sheets
    By ElPolloDiablo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-20-2015, 03:47 AM
  4. Copy Rows by Cell Value, Paste to Newly Created Worksheet, Email Contents
    By TylerK_BLL in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-09-2015, 03:40 PM
  5. Paste into newly created tab
    By robertc12 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-21-2009, 03:27 PM
  6. [SOLVED] Can't find newly created userform
    By Benz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-13-2006, 12:30 PM
  7. add list to newly created menu
    By Anthony in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-24-2005, 09:06 PM

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