Avatar of cnl83
cnl83
Flag for United States of America asked on

Macro not working on all the way through the document

MacroEE.xlsmAttached is an excel 2010 document with a Macro. The macro is designed to combine multiple rows with the same employee ID and total the points. This worked the last time I used it, but on this particular document it only works up to a certain point. If you hit CTRL T it will run the macro. I can't tell where its stopping or see any inconsistencies that would cause it to not stop.

After the macro runs, we should end up with about 800-1000 records.

<<Code added by byundt--Microsoft Excel Zone Advisor 5-22-12 so question would make sense without sample workbook>>
Sub David_Macro()
'
' David_Macro Macro
' Combine Rows and Total Points
'

'
Dim RowCount As Long
Dim i As Long
Dim j As Long

'Find out how many rows have data
RowCount = ActiveSheet.Range("A:A").End(xlDown).Row

For i = 2 To RowCount
    ' If a row value in col E is the same as the next row then...
    If Range("E" & i).Value = Range("E" & i + 1).Value Then
        ' ...start looking for all rows that follow it that have the same value
        For j = i + 1 To RowCount
            If Range("E" & j).Value = Range("E" & i).Value Then
                ' We've found one that's the same so add the value in column C to the first one
                Range("C" & i).Value = Range("C" & i).Value + Range("C" & j).Value
                ' Mark the row we just used for later deletion
                Range("K" & j).Value = "DELETE"
            Else
                Exit For
            End If
        Next
        i = j - 1
    End If
Next

' Delete the marked rows
For i = RowCount To 2 Step -1
    If Range("K" & i).Value = "DELETE" Then
        Rows(i & ":" & i).Select
        Selection.Delete Shift:=xlUp
    End If
Next
End Sub

Open in new window

Microsoft ExcelVB ScriptSpreadsheets

Avatar of undefined
Last Comment
byundt

8/22/2022 - Mon
Saqib Husain

Any chance there is a blank  cell within column A?
SOLUTION
Norie

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
redmondb

Apologies, imnorie, crossing posts.
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck