+ Reply to Thread
Results 1 to 7 of 7

Caught in a loop that errors

  1. #1
    Registered User
    Join Date
    04-24-2019
    Location
    San Diego, Ca
    MS-Off Ver
    Office 16
    Posts
    4

    Caught in a loop that errors

    Thank you in advance for looking at this file and providing any assistance. I have a file with VBA designed in Excel 2010. I upgraded to Office 2016 and started getting an error Method 'Range' of object'_Global' failed when I try to sort from the waterfall page. I am far from expert and have walked through this a few times but not sure why.
    Attached Files Attached Files

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

    Re: Caught in a loop that errors

    How are you doing the sorting?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    04-24-2019
    Location
    San Diego, Ca
    MS-Off Ver
    Office 16
    Posts
    4

    Re: Caught in a loop that errors

    Thanks for your reply. I have 4 option buttons that allow it to sorted by Airport, Type, Pub date, or alphabetically. depending on the button selected, the sub sorts by that criteria from a data page.
    It then cuts and refers to watefall page and cuts and paste the data in that order on the waterfall. The portion that errors is show below.
    'find bottom row on waterfall

    With Sheets("Waterfall")
    lastspot = .Cells(.Rows.Count, "A").End(xlUp).Row
    newtop = lastspot + 1
    Range("A8", "AV" & lastspot).Select
    Selection.Cut
    Range("A" & newtop).Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    newbottom = .Cells(.Rows.Count, "A").End(xlUp).Row
    spot = 8

    For Count = 1 To UBound(SortOrder, 2)
    Counter = newtop
    Do Until Range("I" & Counter).Value = SortOrder(1, Count)

    Counter = Counter + 1
    Loop
    movespot = Counter - 2

    Range("A" & movespot, "AV" & movespot + 11).Select
    Selection.Cut
    Range("A" & spot).Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    spot = spot + 12
    Next

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

    Re: Caught in a loop that errors

    The reason that code errors is because Counter reaches 1048577 and there are only 1048576 rows on an Excel worksheet.

    Why it Counter reaches that value I'm not 100% sure, is it a particular option button that's causing the problem?

  5. #5
    Registered User
    Join Date
    04-24-2019
    Location
    San Diego, Ca
    MS-Off Ver
    Office 16
    Posts
    4

    Re: Caught in a loop that errors

    It is weird. It does not matter which button I use to sort. I noticed that when the error happens the sorting happens on the Data (hidden) worksheet rather than the waterfall. That seems to cause the error. Why it does not get back to the waterfall page and sort I do not understand. If I take the time to move the information on the data page back to the table it will run correctly. Occasionally it will sort correctly on its own. I am perplexed.

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

    Re: Caught in a loop that errors

    I only had a quick look at your code yesterday but I seem to recall that there were quite few unqualified range references.

    When a range reference is unqualified it will refer to the active sheet and that could explain the problem, and why moving data seems to fix things.

    The 'proper' way to avoid an error like this is to make sure you qualify things properly.

    I'll take a closer look at the code later and try and post something to show what I mean.

  7. #7
    Registered User
    Join Date
    04-24-2019
    Location
    San Diego, Ca
    MS-Off Ver
    Office 16
    Posts
    4

    Re: Caught in a loop that errors

    Thank you for your help.

+ 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] Error doesn't get caught
    By JasperD in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-14-2017, 09:05 AM
  2. [SOLVED] Refresh Pivot - caught in a loop
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-18-2011, 09:42 AM
  3. Macro getting caught in loop
    By HuskerBronco in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-13-2009, 03:14 PM
  4. Excel caught looping script
    By realniceguy5000 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-12-2008, 02:55 PM
  5. What to say if you're caught asleep at your desk
    By Trebor76 in forum The Water Cooler
    Replies: 1
    Last Post: 07-25-2008, 03:32 AM
  6. Loop EOF errors
    By diannk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-23-2008, 03:13 PM
  7. Caught in an Infinite Loop
    By mgri in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-02-2007, 10:14 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