+ Reply to Thread
Results 1 to 6 of 6

Create a new sheets based upon the value in the range and gotot next cell if sheet exists

  1. #1
    Registered User
    Join Date
    01-31-2018
    Location
    New Jersey
    MS-Off Ver
    2016
    Posts
    17

    Create a new sheets based upon the value in the range and gotot next cell if sheet exists

    Hi Guys,

    I am having problem. I am able to create new sheets having name as per cell values but I am unable to do that if I add new value at last and run the script. Below is the script that I am working

    Sub AddSheets()

    Dim xRg As Excel.Range
    Dim wSh As Excel.Worksheet
    Dim wBk As Excel.Workbook
    Set wSh = ActiveSheet
    Set wBk = ActiveWorkbook
    Application.ScreenUpdating = False

    For Each xRg In wSh.Range("C14:C30")

    If Not IsEmpty(xRg.Value) Then

    With wBk

    Worksheets("S1").Copy after:=.Sheets(.Sheets.Count)

    On Error Resume Next
    ActiveSheet.Name = xRg.Value
    On Error GoTo 10
    If Err.Number = 1004 Then
    Debug.Print xRg.Value & " already used as a sheet name"

    End If
    On Error GoTo 0
    End With

    End If

    Next xRg

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Create a new sheets based upon the value in the range and gotot next cell if sheet exi

    Quote Originally Posted by pm.patel189 View Post
    I am unable to do that if I add new value at last
    I don't understand what that means; "add new value at last".
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    01-31-2018
    Location
    New Jersey
    MS-Off Ver
    2016
    Posts
    17

    Re: Create a new sheets based upon the value in the range and gotot next cell if sheet exi

    Here is example:

    I have Company1 in C14 cell and Company2 in C15 cell and when I run this script then this creates two new sheets having name Company1 and Company2. But when I add Company3 in C16 Cell and run the script then,

    It creates 3 new sheet S1(1), S1(2), Company3. I dont want that, instead it should create just 1 new sheet Company3

  4. #4
    Registered User
    Join Date
    01-31-2018
    Location
    New Jersey
    MS-Off Ver
    2016
    Posts
    17

    Re: Create a new sheets based upon the value in the range and gotot next cell if sheet exi

    Quote Originally Posted by AlphaFrog View Post
    I don't understand what that means; "add new value at last".
    Here is example:

    I have Company1 in C14 cell and Company2 in C15 cell and when I run this script then this creates two new sheets having name Company1 and Company2. But when I add Company3 in C16 Cell and run the script then,

    It creates 3 new sheet S1(1), S1(2), Company3. I dont want that, instead it should create just 1 new sheet Company3

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Create a new sheets based upon the value in the range and gotot next cell if sheet exi

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    01-31-2018
    Location
    New Jersey
    MS-Off Ver
    2016
    Posts
    17

    Re: Create a new sheets based upon the value in the range and gotot next cell if sheet exi

    That worked...!!! Thanks AlphaFrog

+ 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. Replies: 9
    Last Post: 03-28-2017, 08:30 PM
  2. [SOLVED] VBA - Create New Sheets Based on Index Sheet Cell Values with Link to Index Sheet
    By order in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-02-2017, 06:23 PM
  3. Create sheets based on range on one sheet
    By vpan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-13-2016, 01:55 PM
  4. Replies: 4
    Last Post: 07-13-2015, 10:11 AM
  5. return value based on whether value exists in cell range
    By yewhanbaker in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-16-2015, 03:54 PM
  6. How to create and populate sheets based upon cell values in master sheet?
    By mezzopiano1423 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-12-2013, 12:51 PM
  7. Replies: 2
    Last Post: 11-05-2012, 09:28 AM

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