+ Reply to Thread
Results 1 to 10 of 10

Runtime error 9 - subscript out of range error

  1. #1
    Registered User
    Join Date
    07-16-2014
    Location
    Seattle, WA
    MS-Off Ver
    Office 365
    Posts
    67

    Runtime error 9 - subscript out of range error

    Trying to enter info into worksheets with the worksheet name (membername) being pulled from row A in the reference worksheet (scoresheet). The last line throws a error 9 - subscript out of range error

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by kelseygueldalewis; 08-01-2017 at 02:49 PM.

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Runtime error 9 - subscript out of range error

    try
    Please Login or Register  to view this content.
    all range variables must be SET in vba
    namedatacell is declared as a range

    Edit - you seem to be using a lot of variables and you do not need to.
    These alternatives should also do the job

    avoid namedatacell with:
    Please Login or Register  to view this content.
    or go straight there with
    Please Login or Register  to view this content.
    Last edited by kev_; 08-01-2017 at 02:03 PM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Registered User
    Join Date
    07-16-2014
    Location
    Seattle, WA
    MS-Off Ver
    Office 365
    Posts
    67

    Re: Runtime error 9 - subscript out of range error

    Thanks kev_, I tried that and then got a Runtime Error 1004 at that line, then I defined the variable i = 1 and it throws the same original error

    I declared the range variables with SET here

    Please Login or Register  to view this content.
    Last edited by kelseygueldalewis; 08-01-2017 at 02:02 PM.

  4. #4
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Runtime error 9 - subscript out of range error

    Look at my edits and try the final one - it works for me
    -you could also try Activate instead of Select - but it should not make a difference here

  5. #5
    Registered User
    Join Date
    07-16-2014
    Location
    Seattle, WA
    MS-Off Ver
    Office 365
    Posts
    67

    Re: Runtime error 9 - subscript out of range error

    That certainly made things easier, but it still throws error 9 on this line

    EDIT

    I removed the variables and tried activate but neither did the trick for me. hmm

  6. #6
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Runtime error 9 - subscript out of range error

    Does the worksheet exist?

    Go into VBA and click on "View" then "Immediate Window"
    An extra window is opened up and you can test things there

    immediately below line
    Please Login or Register  to view this content.
    insert these lines

    Please Login or Register  to view this content.
    and remove the line where you are selecting the sheet (the line with the error)

    You shoulsd always see a pair of values in the immediate window
    If the first does not show and the 2nd does for any pair, that worksheet does not exist - (typo?)

  7. #7
    Registered User
    Join Date
    07-16-2014
    Location
    Seattle, WA
    MS-Off Ver
    Office 365
    Posts
    67

    Re: Runtime error 9 - subscript out of range error

    Interesting, the first line gave the same error, so I switched the order. The scoresheet.Range().Value gave me 2 2 0 in the immediate window. Is this considered a pair?

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    EDIT
    I'm trying to reference a worksheet named Members as indicated by this line
    Please Login or Register  to view this content.
    and a Members worksheet definitely exists
    Last edited by kelseygueldalewis; 08-01-2017 at 02:42 PM.

  8. #8
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Runtime error 9 - subscript out of range error

    Number 2 at the beginning identifies the debug line
    The 2nd 2 is the value of i
    The 3rd value is what is in the cell
    So you appear to be telling VBA to select sheet named 0 (zero) or possibly Sheet(0) ie the zeroeth sheet - which does not exist

    If the line beginning 1 (ie the first debug line) did not print to screen it is because that sheet does not exist and VBA cannot tell you its name

    Please Login or Register  to view this content.
    should return the name of the sheet called whatever the value in A & i is
    - and so VBA should give you the same answer as the other debug line
    Last edited by kev_; 08-01-2017 at 02:44 PM.

  9. #9
    Registered User
    Join Date
    07-16-2014
    Location
    Seattle, WA
    MS-Off Ver
    Office 365
    Posts
    67

    Re: Runtime error 9 - subscript out of range error

    oh! Okay I'm realizing now that this is saying that i = 2 and the value in cell A2 at this point is 0, when it should be the name...I think the error here is that the i needs to stand for the column and not the row.

    How can I use the column number as a variable for the Range object? Range(1,i) is throwing a 1004 error

    EDIT

    Alright I can use cells to get the output I am looking for and it worked!

    The issue was I wasn't referencing the sheet name I was referencing a value in a lookup table.
    Last edited by kelseygueldalewis; 08-01-2017 at 02:48 PM.

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

    Re: Runtime error 9 - subscript out of range error

    Uses Cells(row, column) instead of Range(address).
    If posting code please use code tags, see here.

+ 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] Runtime error 9 - Subscript out of range
    By sintek in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-27-2016, 01:34 PM
  2. i am getting a subscript out of range runtime error 9
    By jeaniekeen in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-09-2015, 04:51 PM
  3. runtime error 9 subscript out of range help
    By skate1991 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-24-2014, 02:37 PM
  4. Runtime Error - Subscript out of Range / Object Error
    By JHRice in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-04-2012, 05:14 PM
  5. 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
  6. Runtime Error 9: Subscript out of Range
    By murugavelmsc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-11-2011, 12:33 AM
  7. 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

Tags for this Thread

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