+ Reply to Thread
Results 1 to 9 of 9

Unusual "subscript out of range error" on userform initialise

  1. #1
    Registered User
    Join Date
    08-04-2013
    Location
    Brisbane
    MS-Off Ver
    Excel for Mac 2021
    Posts
    97

    Unusual "subscript out of range error" on userform initialise

    Hi everyone.

    I'm having a very unusual problem and I'm really hoping that someone might have some ideas. I have been at this for hours and I can't seem to find this particular problem anywhere on the forums.

    I'm getting a "Subscript out of range" error when a userform initialises and populates itself with checkboxes.

    The thing is, the error is not displayed when the row count (in the form of the variable "i") is below 41. However, when it tries to add the checkbox for 41, I get the error.

    I'm very confused. Please help!

    Here is the code:

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Unusual "subscript out of range error" on userform initialise

    What's cBox?

    Try this perhaps the rows are not been counted correctly.

    Please Login or Register  to view this content.
    Thanks

  3. #3
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Unusual "subscript out of range error" on userform initialise

    Where are you declaring the cBox variable? How is it dimensioned?
    It also appears that the first created checkbox, cBox(3) has a .Top value of -2.

    Rather than adding all those checkboxes, have you considered using a multi-select Listbox. Event code for existing controls is much easier than for run-time created controls.

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  4. #4
    Registered User
    Join Date
    08-04-2013
    Location
    Brisbane
    MS-Off Ver
    Excel for Mac 2021
    Posts
    97

    Re: Unusual "subscript out of range error" on userform initialise

    Thank you both very much for your replies!

    I didn't realise I forgot to include that variable.
    Please Login or Register  to view this content.
    This is dimmed as a public variable and as I'm writing this I realise the problem. At two in the morning, my tired brain overlooked this! Obviously the iterations couldn't extend beyond the value that I had set - 40.

    Mikerickson, I had never used a multi-select Listbox before. That is incredibly helpful - much simpler! Thank you for taking the time to show me how that works.

    Many, many thanks!

  5. #5
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Unusual "subscript out of range error" on userform initialise

    Just keep in mind that you have 41 spaces in the cBox variable because you need to start counting at "0" (unless you have explicitly said otherwise)



  6. #6
    Registered User
    Join Date
    08-04-2013
    Location
    Brisbane
    MS-Off Ver
    Excel for Mac 2021
    Posts
    97

    Re: Unusual "subscript out of range error" on userform initialise

    One last thing, Mikerickson.

    I am currently using the caption of the checkbox (cBox) later in my code.

    Please Login or Register  to view this content.
    With the multi-select listbox, how would I get the value of the selected list-boxes?

  7. #7
    Registered User
    Join Date
    08-04-2013
    Location
    Brisbane
    MS-Off Ver
    Excel for Mac 2021
    Posts
    97

    Re: Unusual "subscript out of range error" on userform initialise

    Thank you, Fredlo.

  8. #8
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Unusual "subscript out of range error" on userform initialise

    To test if an item in a multi-select ListBox is selected, one uses the .Selected property.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    08-04-2013
    Location
    Brisbane
    MS-Off Ver
    Excel for Mac 2021
    Posts
    97

    Re: Unusual "subscript out of range error" on userform initialise

    Thank you! That is incredibly helpful.

+ 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. Breaking out Comma Delimited Fields - VBA Error - "Subscript out of Range"
    By sev979 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-13-2014, 09:55 AM
  2. Error msgs: "Object varible or with block variable not set"; "subscript out of range"
    By menyanthe in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-26-2009, 04:58 PM
  3. "Subscript out of range" error message when using HPageBreaks.Location
    By Johnny Tong in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-02-2008, 09:35 PM
  4. [SOLVED] "Subscript out of range" error for: Workbooks("Test1.xls").Save
    By Just12341234 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-17-2005, 11:05 AM
  5. FileCopy Command Giving "Subscript Out of Range" Error Message
    By Jim Hagan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-15-2005, 02:05 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