+ Reply to Thread
Results 1 to 5 of 5

Option Base 1 doesn't apply to some arrays?

  1. #1
    Registered User
    Join Date
    03-26-2019
    Location
    Earth
    MS-Off Ver
    2013
    Posts
    3

    Option Base 1 doesn't apply to some arrays?

    In my workbook Declarations, I have these lines of code:

    Please Login or Register  to view this content.
    Later in a Sub I initialize indices as an array:

    Please Login or Register  to view this content.
    In the same Sub I use this array in a For loop:

    Please Login or Register  to view this content.
    However, using a break point on that last line of code reveals that i starts out at a value of 0. i should start out as the lower bound of the indices array, which should be 1 because of the Base Option used in the declarations. Does it fail because indices was not declared as an array?

    If so, is there some way to make indices adhere to the Base Option but not initialize it with successive, single-assignments?

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Option Base 1 doesn't apply to some arrays?

    An excerpt from an MS article on Option Base:
    The To clause in the Dim, Private, Public, ReDim, and Static statements provides a more flexible way to control the range of an array's subscripts. However, if you don't explicitly set the lower bound with a To clause, you can use Option Base to change the default lower bound to 1. The base of an array created with the ParamArray keyword is zero; Option Base does not affect ParamArray (or the Array function, when qualified with the name of its type library, for example VBA.Array).
    Note the statement in red font. it also does not apply to the Split function which will always return a zero base array.
    Last edited by JLGWhiz; 03-26-2019 at 03:52 PM.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Option Base 1 doesn't apply to some arrays?

    If you've declared indices as Integer and it's still in scope when this code is executed,
    Please Login or Register  to view this content.
    you'll get a type mismatch error.

    Have a look at this code where indices is declared as Variant.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    03-26-2019
    Location
    Earth
    MS-Off Ver
    2013
    Posts
    3

    Re: Option Base 1 doesn't apply to some arrays?

    Note the statement in red font.
    Thanks for the info, but I didn't qualify my use of the Array function with the name its type library.

  5. #5
    Registered User
    Join Date
    03-26-2019
    Location
    Earth
    MS-Off Ver
    2013
    Posts
    3

    Re: Option Base 1 doesn't apply to some arrays?

    Quote Originally Posted by Norie View Post
    If you've declared indices as Integer and it's still in scope ... you'll get a type mismatch error.

    Have a look at this code where indices is declared as Variant.
    That solved it. Thanks!

+ 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] Option Base 1 it still starting from 0 and not 1
    By starlev in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-30-2015, 08:47 AM
  2. [SOLVED] Userform doesn't apply data in correct place! Please HELP!
    By afrabat in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-24-2014, 04:21 PM
  3. [SOLVED] Need to apply conditional formatting of a cell base on text in multiple other cells
    By Herkfixer in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-19-2013, 08:59 PM
  4. [SOLVED] How to check the Option Base state in a Form ?
    By nemo66ro in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-09-2012, 03:35 AM
  5. Option Base
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-24-2011, 01:07 PM
  6. Apply a formula on multiple arrays
    By shamrookh in forum Excel General
    Replies: 1
    Last Post: 07-16-2010, 12:03 PM
  7. Option Base error...
    By pmguerra in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-11-2006, 06:10 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