Results 1 to 18 of 18

VBA Macro not completing it's task.

Threaded View

  1. #1
    Registered User
    Join Date
    08-12-2012
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    47

    VBA Macro not completing it's task.

    Hi, I finally wrote a couple of macros in VBA that I wanted to do and they work but for some reason they do not complete the task properly and I have to run the macro over and over again to finish completely. For instance I wrote a program in VBA to remove rows of data that contain duplicate cells in the same row. This program goes thru a spead sheet row by row and compares the values in the first cell with the next cell, so on and so forth until the whole row is checked for either a duplicate or a value that is higher than the next cell. If either condition is met then the program deletes the row and moves on to the next row checking in the same manner and shifts up to remove the empty rows. But, the program does not complete its task on the first try. For a spreadsheet of about 700 rows it takes about 6 or 7 runs of the macro to remove all duplicates ect... Why is this?

    Here's a copy of the code:

    Option Explicit

    Sub DeleteDupRows()
    
    Dim a As Integer, b As Integer, LastRow As Long
        LastRow = Application.Count(Range("a:a"))
        a = 0
        b = 0
            For a = 1 To LastRow
            b = 1
            Do While b < 6  'The row contains 6 numbers each
                If Cells(a, b).Value >= Cells(a, b + 1).Value Then Cells(a, b).EntireRow.Delete xlUp
                b = b + 1
                Loop
            Next a
                    
    End Sub
    Can anyone tell me why I'm having an issue with incomplete macro tasking?

    Thanks,

    Sebastien.
    Last edited by Cutter; 09-03-2012 at 09:42 AM. Reason: Added code tags

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