+ Reply to Thread
Results 1 to 9 of 9

ListObject Subscript out of range error

Hybrid View

  1. #1
    Registered User
    Join Date
    05-23-2013
    Location
    California
    MS-Off Ver
    Excel 2013
    Posts
    68

    ListObject Subscript out of range error

    Hello, All. Capture.JPG

    I have the table in the image attached. I am trying to pull two adjacent cells out of a row and concat them together. I have several case statements before this for row numbers 2 - 4.

    I have read that the header row is not included in the row count. i.e. row 1 should be the first non-header row in the table. However, I am not seeing that as the reality. When I use ListRows("2") I get data out of the first non-header row.

    My problem is when i get to the case statement below. It says that ListRows("7") is out of range. I dont get it though. If ListRows("2") is the first non-header row and I want the last row in the table...It should be 7. I have included the table resize window as well so that you can see the bounds of the table. any help would be appreciated.

                 Case ratingNum Like "5"
                    Cells(2, 1).Value = ActiveWorkbook.Sheets("How to Use").ListObjects("RatingScale") _
                    .Range(ActiveWorkbook.Sheets("How to Use").ListObjects("RatingScale").ListRows("7").Index, _
                    ActiveWorkbook.Sheets("How to Use").ListObjects("RatingScale").ListColumns("Level Name").Index).Value _
                    & ": " & ActiveWorkbook.Sheets("How to Use").ListObjects("RatingScale") _
                    .Range(ActiveWorkbook.Sheets("How to Use").ListObjects("RatingScale").ListRows("7").Index, _
                    ActiveWorkbook.Sheets("How to Use").ListObjects("RatingScale").ListColumns("Description").Index).Value

  2. #2
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: ListObject Subscript out of range error

    Are you sure that you should not use ListRows(7)? I.e. without the quotes.
    If you like my contribution click the star icon!

  3. #3
    Registered User
    Join Date
    05-23-2013
    Location
    California
    MS-Off Ver
    Excel 2013
    Posts
    68

    Re: ListObject Subscript out of range error

    Thanks for the suggestion OllieB.

    it didnt give a syntax error on that but, 7 was still out of range.

  4. #4
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: ListObject Subscript out of range error

    If the ListRows collection is zero based then ListRows(6) would point to the last row, and ListRows(7) would be out of range

  5. #5
    Registered User
    Join Date
    05-23-2013
    Location
    California
    MS-Off Ver
    Excel 2013
    Posts
    68

    Re: ListObject Subscript out of range error

    Right, totally agree. the problem is that ListRows(1) gives me the header row and ListRows(2) is the first non-header row. ListRows(0) is also out of range.

  6. #6
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: ListObject Subscript out of range error

    *** duplicate post ***

  7. #7
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: ListObject Subscript out of range error

    I have tried to replicate your problem by creating a table and referencing it from VBA. For my solution ListRows(0) points to the header and ListRows(6) refers to the last data row, I would suggest to split the single line of instructions wu=ithin the Case into separate statements to make it easier to debug what is going on. I suspect your problem may be elsewhere in the code

  8. #8
    Registered User
    Join Date
    05-23-2013
    Location
    California
    MS-Off Ver
    Excel 2013
    Posts
    68

    Re: ListObject Subscript out of range error

    OllieB, I will give that a shot. thanks for your help.

  9. #9
    Registered User
    Join Date
    05-23-2013
    Location
    California
    MS-Off Ver
    Excel 2013
    Posts
    68

    Re: ListObject Subscript out of range error

    ListRows(7) was still giving me "out of range" after recreating the table and validating the code. Not the cleanest solution but, I used .ListRows(6).Index + 1 and that returned the correct cells without the "out of range" error. Not the cleanest but, it works for my purposes.

    Thanks for your help, OllieB

+ 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] Run-time error '9': subscript out of range - error occurs on multiple computers except one
    By BrettE in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-06-2014, 11:19 PM
  2. Defining Array - Runtime error 9, Subscript out of range error
    By MaartenW in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-03-2012, 07:32 AM
  3. Runtime Error - Subscript out of range despite On Error statement
    By DoctorG in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-28-2006, 11:05 AM
  4. Subscript out of range error - save copy error
    By bg18461 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-13-2006, 11:53 AM
  5. [SOLVED] Type Mismatch error & subscript out of range error
    By Jeff Wright in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-14-2005, 03: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