+ Reply to Thread
Results 1 to 6 of 6

Loop runs into subscript out of range in the last row?

  1. #1
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Loop runs into subscript out of range in the last row?

    Hi all I have the following code:

    Please Login or Register  to view this content.
    It joins "First Name" and "Last Name" adds it to EDict dictionary as key with no item, unless its already there, if its already there, it should delete the row, but for some reason it runs into Subscript out of range. When I hover my cursor above p, p=89 which is my last row of data in my table.

    I have no clue why this happens.

    Could anyone help please?

    Posted on Mr.Excel Message board as well, link: https://www.mrexcel.com/forum/excel-...ml#post5230667
    Last edited by LIL2606; 02-21-2019 at 01:42 PM.

  2. #2
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: Loop runs into subscript out of range in the last row?

    I have copied it over into another workbook and in that one, it works like a charm.. could it be because I already have another scripting dictionary in my original file?

  3. #3
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: Loop runs into subscript out of range in the last row?

    Just a lucky" guess.. It might have to do with the Else.. part of the if statement.

    lets say you have 50 in the databody range at the start of the loop so the loop is set for 1 to 50 and at row 33 the Else statement is excecuted. then it deletes row 33 resulting in only 49 rows left in databodyrange but because the for loop was set to 50 at the start. there is now no longer a row 50 in the databody range.

  4. #4
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: Loop runs into subscript out of range in the last row?

    Yeah update on this, it actually does the job, only instead of just finishing it runs into the error? ( I only just realized this because some last names had spaces beside them so they stayed and I still had name duplicates by the looks of it)

  5. #5
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: Loop runs into subscript out of range in the last row?

    It probably is what you are saying.. but how does one fix it, and why wasn't it a problem in my other worksheet, where it does the same job?

  6. #6
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: Loop runs into subscript out of range in the last row?

    AAAH because it is stepping backwards there..

+ 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] Loop only runs if-statement one time
    By fokka in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-09-2017, 01:02 PM
  2. [SOLVED] Create Loop that runs until Last Worksheet
    By cbramsey1979 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-24-2017, 10:16 AM
  3. [SOLVED] Getting Subscript out of range error with For Loop when deleting worksheets
    By parodytx in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-14-2015, 04:24 PM
  4. Loop variable subscript out of range
    By maurice1991 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-01-2015, 07:31 AM
  5. Loop runs stuck with sorting
    By nielsBNP in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-17-2013, 10:04 AM
  6. Ok button runs code 17 times w/o loop.... Why?
    By contaminated in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-28-2012, 05:19 AM
  7. [SOLVED] ADO command.execute with a loop - only runs once
    By George King in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-09-2006, 02:35 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