+ Reply to Thread
Results 1 to 7 of 7

Code to add sheets throwing Syntax error

  1. #1
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Code to add sheets throwing Syntax error

    Macro should list all the existing worksheets in a "Scripting Dictionary".

    Code should then compare the Dictionary against the list of names in Col A of sheet 2.

    If there is no sheet with that name, it should add a new sheet after Sheet 1, name it with the name in sheet 2, add the new name to the Dictionary, and check the next name in turn.

    But Code is throwing a Syntax Error, and can't see why?

    Please Login or Register  to view this content.
    All solutions, suggestions and alternatives welcome as ever.

    Ochimus
    Attached Files Attached Files
    Last edited by Ochimus; 06-01-2019 at 06:51 PM.

  2. #2
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,152

    Re: Code to add sheets throwing Syntax error

    Quote Originally Posted by Ochimus View Post
    ... Code is throwing a Syntax Error ...
    'Add sheet to Workbook - Throwing "Syntax error"
    Instead of:
    Please Login or Register  to view this content.
    this:
    Please Login or Register  to view this content.
    Quote Originally Posted by Ochimus View Post
    ... If Not ws(.Range("A" & s)) Then ...
    This is the wrong syntax

    also

    for this command:
    Please Login or Register  to view this content.
    the wrong sheet index will be calculated - always number 2.
    Is this just what should be written in the dictionary ?

  3. #3
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Re: Code to add sheets throwing Syntax error

    porucha vevrku,

    Many thanks for prompt response, but has created a new problem!

    As shown on the attached, I changed the Macro from a Module to a Worksheet Change on Sheet 2, so it will create new sheets automatically if the user adds a new name.

    Starting with just Sheets 1 and 2, I added a new name to Row 8 on sheet 2. Macro ran perfectly and created the new sheet.

    But when I added a second new name to Sheet 2, it not only created the new "names" sheet, but a range of "numbered" sheets as well.

    And when I tried a third new name, the entire Macro stopped working!

    As you can see, I set the Immediate window to ensure Application.EnableEvents = True, as the Macro then sets it to False until it completes, when it resets to True


    Please Login or Register  to view this content.
    Hope someone can "see the wood for the trees"??

    Ochimus
    Attached Files Attached Files

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,094

    Re: Code to add sheets throwing Syntax error

    Try
    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,152

    Re: Code to add sheets throwing Syntax error

    Or maybe without a dictionary ?
    Please Login or Register  to view this content.

  6. #6
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Re: Code to add sheets throwing Syntax error

    Fluff,

    Many thanks.

    Added your change, Macro worked again perfectly.

    Can now mark this as "Solved"

    Ochimus



    Ochimus

  7. #7
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,094

    Re: Code to add sheets throwing Syntax error

    You're welcome & thanks for the feedback

+ 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. [SOLVED] Mac throwing error - Runtime Error 429 - ActiveX Component Can't Create Object
    By harman83 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 11-28-2018, 11:04 PM
  2. Excel Macro throwing a Syntax Error and I am not sure why
    By budwong27 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-14-2017, 03:43 AM
  3. Code Throwing Run Time error...
    By tsiguy96 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-16-2016, 03:59 PM
  4. [SOLVED] VBA code throwing error
    By philozelda in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-17-2015, 02:35 PM
  5. [SOLVED] This Code Is Throwing An Error At The End...
    By Regular_Joe in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-03-2014, 11:15 AM
  6. [SOLVED] Syntax error in code???
    By lundy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-06-2012, 01:39 PM
  7. [SOLVED] Syntax error in code
    By JOUIOUI in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-10-2006, 11:10 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