+ Reply to Thread
Results 1 to 4 of 4

have 1 dimensional array, trying to create a 2 dimensional array, runtime 9

  1. #1
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,411

    have 1 dimensional array, trying to create a 2 dimensional array, runtime 9

    so i have the test code below but im getting a run-time error '9': subscript out of range. it errors on this line: Debug.Print z(w, y)
    when i check the locals window, the 2 dimensional array says z(1,1) and z(1,2) but w is 0 and y is 1. what am i doing wrong?

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,411

    Re: have 1 dimensional array, trying to create a 2 dimensional array, runtime 9

    never mind, i fixed the issue. missed that i had option base 1 at the top of the module.

  3. #3
    Forum Moderator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    365
    Posts
    16,611

    Re: have 1 dimensional array, trying to create a 2 dimensional array, runtime 9

    It is not clear what you are trying to do, and there may be a better overall solution. For starters, you never assign values to any element of z, yet you are printing it out. So you are always going to print 0.

    Note that LBound(t) will be 0, due to what Split returns. So the first value of w in your loop will be 0. If you are using "Option Base 1" at the top of the module, then the first dimension of z will be 1 To UBound(t) and you will get a subscript error.

    I recommend you make your lower bounds explicit and try this:

    Please Login or Register  to view this content.
    but I can't say with 100% certainty because I don't know what this code is supposed to do.

    (Also I highly recommend using variable names that are meaningful, rather than single letters.)

  4. #4
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,411

    Re: have 1 dimensional array, trying to create a 2 dimensional array, runtime 9

    so ya, i did have option base 1 for my test code, but i removed that and the test procedure works great. but when i implement it in my actual code,it fails on: z(w,y)=t(w)

    here is the real code.

    Please Login or Register  to view this content.
    so what should happen is that when the code window opens up (btn_Gen_uf2.show), it parses the text in the textbox and should populate each line into z(w,y). but when i check the local window this time, it shows z(0,0),z(0,1) & z(0,2) and only z(0,1) shows one of the text lines, but the other two are "". i know that sometimes single letters can be confusing so i will try to implement that in the future.

    nevermind, your redim code worked for me. sorry that i glossed over it. thanks
    Last edited by dmcgov; 03-21-2019 at 07:06 AM. Reason: working now

+ 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] Convert 2 dimensional array to 1 dimensional
    By jaryszek in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-19-2018, 05:20 AM
  2. Help converting one-dimensional array to multi-dimensional array
    By puzzlelover22 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-13-2016, 06:48 AM
  3. Parse Data from one dimensional array into a 2 dimensional array.
    By JapanDave in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-30-2016, 07:29 AM
  4. [SOLVED] Convert one dimensional array into two dimensional array
    By mohammed sabr in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-26-2015, 10:34 AM
  5. Replies: 6
    Last Post: 09-25-2013, 10:08 PM
  6. Creating a 2-dimensional array from a 1-dimensional list
    By guywithcamera in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-27-2008, 06:34 PM
  7. Create One-Dimensional Array from Two-Dimensional Array
    By Stratuser in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-23-2005, 05: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