+ Reply to Thread
Results 1 to 7 of 7

Why my code is producing Error "SUBSCRIPT OUT OF RANGE" While using variant arrays?

  1. #1
    Registered User
    Join Date
    07-13-2019
    Location
    Mansehra, Pakistan
    MS-Off Ver
    2010
    Posts
    46

    Why my code is producing Error "SUBSCRIPT OUT OF RANGE" While using variant arrays?

    Hi Everyone!

    I want to Replace negative values with absolute (without Minus sign) in the same column.

    While executing the following code, an error pops up saying "Subscript Out of Range".


    Please Login or Register  to view this content.
    Kindly refer also to the thread http://www.excelforum.com/excel-prog...r-methods.html
    and another thread https://www.excelforum.com/excel-pro...ed-thread.html

    In the original first thread i wanted to to replace to the whole dates with only day, and, in the aforementioned code, i attempted to convert the negative values to the positive ones in the same sheet in Column "E".

    I am writing separate codes for these two tasks. I think this can be solved using Two dimensional dynamic arrays for both the columns in one sub routine, I tried but failed...

    I need your valuable help on:
    1. Rectification on the error "Subscript out of Range".
    2. A Single Procedure for replacing whole dates with only "Day" in Column "D" and Converting negative numbers to Positive Ones in Column "E", specifically using two dimensional dynamic arrays if possible.

    P.S: If i need to start separate thread for 2nd point above, please let me know. I would ask the same question in separate thread otherwise any help here would be highly appreciated.

    Sample workbook can be downloaded from the links pasted above.

    Thanks all

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Why my code is producing Error "SUBSCRIPT OUT OF RANGE" While using variant arrays?

    Change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    07-13-2019
    Location
    Mansehra, Pakistan
    MS-Off Ver
    2010
    Posts
    46

    Re: Why my code is producing Error "SUBSCRIPT OUT OF RANGE" While using variant arrays?

    Thanks for help!

    What's the difference between using "LastRow" and "Ubound(MyAmount)"?
    Why using "LastRow" produces error while ubound(MyAmount) does not?
    Both are producing the same result i.e. Row 129...

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Why my code is producing Error "SUBSCRIPT OUT OF RANGE" While using variant arrays?

    LastRow is from the worksheet
    Please Login or Register  to view this content.
    You load the data into Array
    Please Login or Register  to view this content.
    Whatever the start cells "E2" in this case, row reference in Array starts from 1, so the size of the array is actually LastRow - 2 + 1, so not LastRow in this case.
    If you want to loop all though to the end of the array, UBound function always return the last row index within an array.

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Why my code is producing Error "SUBSCRIPT OUT OF RANGE" While using variant arrays?


    Hi,

    'cause using LastRow is a logical error according to the array indexes like you can easily check via the VBE Locals windows …

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Why my code is producing Error "SUBSCRIPT OUT OF RANGE" While using variant arrays?

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    07-13-2019
    Location
    Mansehra, Pakistan
    MS-Off Ver
    2010
    Posts
    46

    Re: Why my code is producing Error "SUBSCRIPT OUT OF RANGE" While using variant arrays?

    Yes, Understood...

    In my code Last Row has value of 130, while, the size of Array is 129 as i deducted 1 before loading data into array.
    So, either Ubound(MyAmount)or Adjusting LastRow as indicated by Jindon would solve the problem.

    Many Thanks to all the contributors here.

    Much Appreciated!!!

+ 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 error" in a simple code
    By Mutak in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-30-2016, 04:35 PM
  2. [SOLVED] getting Error 9 "Subscript out of range" with code
    By H_Kennedy in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 01-06-2014, 08:37 PM
  3. Error "Subscript out of range", cant seem to find where code is wrong
    By KeithMale in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-14-2013, 07:07 PM
  4. [SOLVED] trying to understand why a code is not working "error 9 subscript out off range"
    By cdafonseca in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-09-2013, 12:33 PM
  5. [SOLVED] Can't debug this code. The Arrays are producing a Subscript out of Range error
    By seigna in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-06-2013, 05:14 PM
  6. Error msgs: "Object varible or with block variable not set"; "subscript out of range"
    By menyanthe in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-26-2009, 04:58 PM
  7. "Subscript out of range" error for: Workbooks("Test1.xls").Save
    By Just12341234 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-17-2005, 11:05 AM

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