+ Reply to Thread
Results 1 to 6 of 6

Naming new sheets with an input box with a dynamic text string in the prompt

  1. #1
    Forum Contributor
    Join Date
    03-01-2019
    Location
    New York, New York
    MS-Off Ver
    Office 2016 for Mac
    Posts
    125

    Naming new sheets with an input box with a dynamic text string in the prompt

    I would like the below code to work as intended. At the moment it inserts "second", "third", etc. into the WsName prompt (e.g. What's the name of the second sheet?). I can't figure out why it is skipping the first member of the ShtCount array ("first").

    Here is the code:

    Please Login or Register  to view this content.

  2. #2
    Registered User
    Join Date
    08-27-2019
    Location
    Alabama, USA
    MS-Off Ver
    365, 2016, 2010, 2007
    Posts
    57

    Re: Naming new sheets with an input box with a dynamic text string in the prompt

    The way many computers(programs) count, starts at zero. You might try changing the following:
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    I suspect that the "first" element is element 0, "second" is element 1, etc...

    EDIT:14:37
    Also do the same to the next part:
    Please Login or Register  to view this content.
    change to
    Please Login or Register  to view this content.
    Last edited by spencer_time; 09-26-2019 at 03:38 PM.

  3. #3
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,463

    Re: Naming new sheets with an input box with a dynamic text string in the prompt

    Arrays produced by the Array function start at index 0, not 1 by default. So, you could either subtract 1 from the index value for calls to the ShtCount array or you could put this at the top of your code window to force the Array function to start at index 1...

    Option Base 1

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,692

    Re: Naming new sheets with an input box with a dynamic text string in the prompt

    spencer_time nailed it right on.
    If you want to start with 1 being the first item, you need to use "Option Base 1" at the top of your code window.
    https://docs.microsoft.com/en-us/off...base-statement

  5. #5
    Forum Contributor
    Join Date
    03-01-2019
    Location
    New York, New York
    MS-Off Ver
    Office 2016 for Mac
    Posts
    125

    Re: Naming new sheets with an input box with a dynamic text string in the prompt

    Thank you! I did not know that and didn't know I could use the Option Base 1. You guys are awesome!

  6. #6
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,463

    Re: Naming new sheets with an input box with a dynamic text string in the prompt

    Quote Originally Posted by Ianmacros View Post
    Thank you! I did not know that and didn't know I could use the Option Base 1. You guys are awesome!
    One note about Option Base 1... it does not work for an array produced by the Split function... the Split function always returns a zero-based array independent of the Option Base setting.
    Last edited by Rick Rothstein; 09-26-2019 at 06:43 PM.

+ 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. Add text instruction to a cell to prompt for input
    By Rocky2013 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-20-2017, 05:58 PM
  2. Replies: 2
    Last Post: 10-18-2016, 12:05 AM
  3. [SOLVED] Prompt save and use certain naming convention
    By lemonap618 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-27-2016, 02:08 AM
  4. [SOLVED] Length of string, not value related to string appearing in input box prompt.
    By ColdDay in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-23-2014, 05:32 PM
  5. Input box on click of cell that contains dynamic text.
    By Nic31 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-27-2014, 01:27 PM
  6. Search for any string / text greater than AND for string / text less than input box
    By JaneinExcel in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-11-2013, 04:18 PM
  7. [SOLVED] Macro to manually input which field (column) to autofilter on using an input prompt
    By rin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-21-2012, 09:35 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