+ Reply to Thread
Results 1 to 7 of 7

Run-time error '9' : Subscript out of range . Some data works, Some do not work

  1. #1
    Registered User
    Join Date
    01-28-2021
    Location
    Kedah
    MS-Off Ver
    2016
    Posts
    40

    Run-time error '9' : Subscript out of range . Some data works, Some do not work

    Hi,

    I have macro problem "Run-time error '9' : Subscript out of range".
    The macro works in some data, some data need macro changes, some data do not work at all.

    The excel file in attachment. have 3 sheet, "Monday", "Tuesday" and "Friday".

    1) Sheet "Monday" : Works with original macro ( no changes).
    2) Sheet "Tuesday" : Works with changes
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    3) Sheet "Friday" : Not work with original macro or changes.

    What is macro do is finding number pattern of Plus-Zero-Minus (+0-) then assign "1" at the start of pattern.
    The data, original macro and change macro included in file excel.

    Excel File : https://www.mediafire.com/file/12p3t...acro.xlsb/file

    Original Code:
    Please Login or Register  to view this content.
    Change Code:
    Please Login or Register  to view this content.
    Last edited by your; 05-30-2024 at 10:42 AM.

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,955

    Re: Run-time error '9' : Subscript out of range . Some data works, Some do not work

    Why not just...
    Please Login or Register  to view this content.
    Your initial code is also flagging (+00)
    Last edited by Sintek; 05-30-2024 at 10:31 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Registered User
    Join Date
    01-28-2021
    Location
    Kedah
    MS-Off Ver
    2016
    Posts
    40

    Re: Run-time error '9' : Subscript out of range . Some data works, Some do not work

    Number of "0" are random. Minimum is 1 (+0-), there might 2/3/4 "0"s, etc... ( +00- , +000-, +0000-),etc..
    But for number of starting +(Plus) and ending -(Minus) is 1 only.

    Below code is designed to assign "1" at the end of pattern, Works 100% for all data. :
    Please Login or Register  to view this content.
    The problem is to assign "1" at the start of pattern.
    Last edited by your; 05-30-2024 at 10:39 AM.

  4. #4
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,955

    Re: Run-time error '9' : Subscript out of range . Some data works, Some do not work

    Plus-Zero-Minus (+0-)
    Above does not refer...Anyway...Not to worry...Who provided initial code?
    Please Login or Register  to view this content.
    Last edited by Sintek; 05-30-2024 at 10:46 AM.

  5. #5
    Registered User
    Join Date
    01-28-2021
    Location
    Kedah
    MS-Off Ver
    2016
    Posts
    40

    Re: Run-time error '9' : Subscript out of range . Some data works, Some do not work

    Some data, cell E2 is empty but some data E2 contain value.
    It does not matter if E2 contain value or not (can be ignore) because I interested to analyze data start at row 3.
    Last edited by your; 05-30-2024 at 10:54 AM.

  6. #6
    Registered User
    Join Date
    01-28-2021
    Location
    Kedah
    MS-Off Ver
    2016
    Posts
    40

    Re: Run-time error '9' : Subscript out of range . Some data works, Some do not work

    Quote Originally Posted by Sintek View Post
    For i = 1 To UBound(a, 1) - 2
    It works. Thank you very much.
    May I know what the difference between original code, minus -1 and minus -2?

  7. #7
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,955

    Re: Run-time error '9' : Subscript out of range . Some data works, Some do not work

    Loop stops at 3rd from bottom

+ 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. Subscript out of Range ? Run time error 9
    By Skullypots in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-20-2024, 10:32 AM
  2. Error code "run time error 9: subscript out of range
    By iBennett93 in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 06-28-2021, 05:03 AM
  3. 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
  4. Run-time error '9': Subscript out of range
    By ndsutherland in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-26-2014, 01:43 AM
  5. Run-Time error '9' Subscript out of range
    By wahi00 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-29-2014, 09:56 PM
  6. [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
  7. [SOLVED] Run-time Error '9': Subscript out of Range
    By Veena Anoohya in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-19-2014, 05:06 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