+ Reply to Thread
Results 1 to 12 of 12

Getting Run Time Error 9: Sub script out of Range.

  1. #1
    Registered User
    Join Date
    04-01-2015
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    10

    Getting Run Time Error 9: Sub script out of Range.

    I am trying to compare two columns from two different sheets. I cannot use conditional formatting because then it does allow you to use VBA macros for that cells. Basically, I have my second sheet highlighted in blue and if a match is found in second it will reset the color to none. Below is my code.

    Sub Nav()


    Dim ws1 As Worksheet
    Dim ws2 As Worksheet


    Set ws1 = Worksheets("Controller")
    Set ws2 = Worksheets("Order Conversion")
    For Each i In ws1.Range("B2:B3000")
    For Each C In ws2.Range("A2:A3000")
    If i.Cells.Value = C.Cells.Value Then
    C.Cells.Interior.ColorIndex = xlNone
    End If
    Next i
    Next C
    End Sub

    In the both the sheets I have data till row #500 but I want to get this done by 3000 rows because data is updated everyday in sheet one.

    Any help please.
    Thanks.

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Getting Run Time Error 9: Sub script out of Range.

    Please use code tags when posting.

    Maybe?

    Please Login or Register  to view this content.

  3. #3
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Getting Run Time Error 9: Sub script out of Range.

    See if this works for you. If not maybe you can post the sheet.

    Please Login or Register  to view this content.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  4. #4
    Registered User
    Join Date
    04-01-2015
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    10

    Re: Getting Run Time Error 9: Sub script out of Range.

    Hi Skywriter,
    I tried your code but it give me " Invalid Next Control Variable reference" and highlights at Next i.

    Sorry, I am pretty new to this programming world.

    Could you please help.

  5. #5
    Registered User
    Join Date
    04-01-2015
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    10

    Re: Getting Run Time Error 9: Sub script out of Range.

    Quote Originally Posted by JOHN H. DAVIS View Post
    Please use code tags when posting.

    Maybe?

    Please Login or Register  to view this content.
    Hi , it is still giving subscript out of range error.

    thanks

  6. #6
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Getting Run Time Error 9: Sub script out of Range.

    Quote Originally Posted by navbains View Post
    Hi Skywriter,
    I tried your code but it give me " Invalid Next Control Variable reference" and highlights at Next i.

    Sorry, I am pretty new to this programming world.

    Could you please help.
    Read above the code in Post #3.

  7. #7
    Registered User
    Join Date
    04-01-2015
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    10

    Re: Getting Run Time Error 9: Sub script out of Range.

    Quote Originally Posted by skywriter View Post
    Read above the code in Post #3.
    Hi I have attached the file.

    Thanks
    Nav
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Getting Run Time Error 9: Sub script out of Range.

    Quote Originally Posted by navbains View Post
    Hi , it is still giving subscript out of range error.

    thanks
    Double check the spelling of your sheets name to ensure they match the actual names in your workbooks. Also are both worksheets in the same workbook?

  9. #9
    Registered User
    Join Date
    04-01-2015
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    10

    Re: Getting Run Time Error 9: Sub script out of Range.

    Quote Originally Posted by JOHN H. DAVIS View Post
    Double check the spelling of your sheets name to ensure they match the actual names in your workbooks. Also are both worksheets in the same workbook?
    Yeah, I checked. They are same.

    Thanks

  10. #10
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Getting Run Time Error 9: Sub script out of Range.

    Quote Originally Posted by navbains View Post
    Yeah, I checked. They are same.

    Thanks

    No they are not the same. John was right, you have a space after order conversion. Also the C loop should be the first in the next statement. See my change.

    So either take the space out after the sheet name or go into the code and add a space after the sheet name and before the ". Then run this code, or John's whichever is your choice. But if you run his you have to do the same thing either fix the sheet name or add the space in the code.

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    04-01-2015
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    10

    Re: Getting Run Time Error 9: Sub script out of Range.

    Quote Originally Posted by skywriter View Post
    No they are not the same. John was right, you have a space after order conversion. Also the C loop should be the first in the next statement. See my change.

    So either take the space out after the sheet name or go into the code and add a space after the sheet name and before the ". Then run this code, or John's whichever is your choice. But if you run his you have to do the same thing either fix the sheet name or add the space in the code.

    Please Login or Register  to view this content.
    Wooww.. Thanks a lot guys. I was struggling with this from past one day. Both you have a great long weekend. I just learned a lesson here, the main step for programming world is attention to detail.

    Happy Easter Holidays.

  12. #12
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Getting Run Time Error 9: Sub script out of Range.

    Quote Originally Posted by navbains View Post
    Wooww.. Thanks a lot guys. I was struggling with this from past one day. Both you have a great long weekend. I just learned a lesson here, the main step for programming world is attention to detail.

    Happy Easter Holidays.
    Thanks for the feedback and rep points. I've been where you were many times and more often than not it's a misspelling or an unnoticed space. The fact that you had the next i and next c out of order slipped by me the first time and who knows how long it would have taken me to find the space in your tab name if John hadn't said something about the spellings. In this case because of him I looked at it immediately. Remember a space is a character to Excel, so technically they were spelled differently.

    Please go to the Thread Tools drop down box above your original post and choose to mark this post as solved.

    Good Luck!!!
    Last edited by skywriter; 04-02-2015 at 03:28 PM.

+ 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] Script Out of Range Error
    By elevate_yourself in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 10-28-2014, 12:58 PM
  2. [SOLVED] Script out of Range Error
    By elevate_yourself in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 10-10-2014, 11:42 AM
  3. run time error 9: script out of range?
    By sanjayrshn.hzb in forum Hello..Introduce yourself
    Replies: 2
    Last Post: 08-04-2014, 05:38 PM
  4. [SOLVED] Run Time Error 9 " Script out of range
    By vaibhav2312 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-10-2013, 08:10 AM
  5. Course Bookings Run-time error '9': Script out of range
    By tomsmart@smart- in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-18-2008, 10:45 PM

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