+ Reply to Thread
Results 1 to 5 of 5

Run Time Error 9 - Subscript out of range

Hybrid View

  1. #1
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Run Time Error 9 - Subscript out of range

    Hi,

    I have a subroutine that was working fine yesterday when I finished up, but now when I run it today I get the run-time error. Any ideas?
    Public Col(1 To 14) As Long
    Public lst As ListObject
    
    Sub GetHeaders()
        
        'This sub is run when the workbook is first open and populates the column variables
        'These are parsed to the report subs below and means the columns can be rearranged
        'But the reports will still filter on the right columns
        Set lst = ActiveSheet.ListObjects("tbl_DHS")
        
        Col(1) = Application.Match("Report SLA A", lst.HeaderRowRange, 0)
        Col(2) = Application.Match("Date of First Contact Attempt", lst.HeaderRowRange, 0)
        Col(3) = Application.Match("Report SLA B", lst.HeaderRowRange, 0)
        Col(4) = Application.Match("Contact Date to Schedule Appointment", lst.HeaderRowRange, 0)
        Col(5) = Application.Match("Report SLA D", lst.HeaderRowRange, 0)
        Col(6) = Application.Match("DMA Referral Appointment Attendance Date", lst.HeaderRowRange, 0)
        Col(7) = Application.Match("Report SLA G", lst.HeaderRowRange, 0)
        Col(8) = Application.Match("DNA 1 date (new)", lst.HeaderRowRange, 0)
        Col(9) = Application.Match("Report Telephone", lst.HeaderRowRange, 0)
        Col(10) = Application.Match("Report SLA E", lst.HeaderRowRange, 0)
        Col(11) = Application.Match("DMA Report Received Date", lst.HeaderRowRange, 0)
        Col(12) = Application.Match("Report SLA F", lst.HeaderRowRange, 0)
        Col(13) = Application.Match("Resubmission date", lst.HeaderRowRange, 0)
        Col(14) = Application.Match("DMA Report Returned to Provider Date", lst.HeaderRowRange, 0)
        
    End Sub

  2. #2
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: Run Time Error 9 - Subscript out of range

    Figured it out, I needed to make my worksheet active first.

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,914

    Re: Run Time Error 9 - Subscript out of range

    Or you can refer to the sheet which holds the table.
    For instance
    Set lst = Sheets("Sheet1").ListObjects("tbl_DHS")
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  4. #4
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: Run Time Error 9 - Subscript out of range

    Great. Tested this and it works too. Thanks!

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,914

    Re: Run Time Error 9 - Subscript out of range

    You're welcome and thanks for rep+.

+ 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
    By exec_gerbil in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 02-22-2024, 12:40 AM
  2. Run Time Error 9: Subscript out of range
    By Pauly723 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-05-2015, 06:09 PM
  3. [SOLVED] Run Time Error : Subscript out of range 9
    By excel_126 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-17-2014, 04:12 AM
  4. Subscript out of range- Run time Error
    By astha.malik1 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 03-19-2014, 10:22 AM
  5. [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
  6. [SOLVED] subscript out of Range (Run time error 9), need help
    By shiva_reshs in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-05-2013, 02:31 PM
  7. Run Time Error 9: Subscript Out of Range
    By jason_kelly in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-14-2011, 01:44 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