Results 1 to 6 of 6

Macro getting caught in loop

Threaded View

HuskerBronco Macro getting caught in loop 09-13-2009, 12:00 PM
Leith Ross Re: Macro getting caught in... 09-13-2009, 12:36 PM
JBeaucaire Re: Macro getting caught in... 09-13-2009, 12:38 PM
HuskerBronco Re: Macro getting caught in... 09-13-2009, 01:15 PM
Leith Ross Re: Macro getting caught in... 09-13-2009, 02:53 PM
HuskerBronco Re: Macro getting caught in... 09-13-2009, 03:14 PM
  1. #1
    Forum Contributor
    Join Date
    01-12-2004
    Location
    Nebraska, USA
    MS-Off Ver
    Office 365
    Posts
    167

    Macro getting caught in loop

    Hello...

    I have the following code pasted into Module 1 in my PERSONAL.xls workbook:

    Sub Delete_Empty_Rows()
    ' DELETE BLANK ROWS FROM CURRENT SPREADSHEET
    
        Dim LastRow As Long
        Dim CurrentRow As Long
        
    ' FIND THE LAST ROW POPULATED WITH DATA IN COLUMN A
        With ActiveSheet
            LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
        End With
    
    ' LOOP FROM ROW 1 TO LAST ROW OF DATA
        For CurrentRow = 1 To LastRow
        
    ' USE DO WHILE IN CASE THERE ARE TWO CONSECUTIVE BLANK ROWS
        Do While IsEmpty(Cells(CurrentRow, 1))
           Rows(CurrentRow & ":" & CurrentRow).Select
           Selection.Delete Shift:=xlUp
        Loop
    Next CurrentRow
    
    End Sub
    When the macro is run...it deletes blank rows on the active worksheet.
    Everything works fine until the macro reaches the LAST ROW in Column A.

    At that point...the macro should stop...but it seems to continue running.

    What am I doing wrong??

    (A sample file has been attached)
    Attached Files Attached Files
    Last edited by HuskerBronco; 09-13-2009 at 03:16 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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