Hi Everyone,
I have a problem with stopping the execution of a macro in Excel. I don’t know if I’m stuck in an infinite loop or what.
Can someone please give me some guidance?
Ever
Here is the code that I’m using. This code finds duplicates in a Range and then shifts up to account for missing row. But it gets frozen.
VB Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim iListCount As String Dim iCtr As Integer ' Get count of records to search through. iListCount = Sheets("Sheet1").Range("A1:A100").Rows.Count Sheets("Sheet1").Range("A1").Select ' Loop until end of records. Do Until ActiveCell = "" ' Loop through records. For iCtr = 1 To iListCount ' Don't compare against yourself. ' To specify a different column, change 1 to the column number. If ActiveCell.Row <> Sheets("Sheet1").Cells(iCtr, 1).Row Then ' Do comparison of next record. If ActiveCell.Value = Sheets("Sheet1").Cells(iCtr, 1).Value Then ' If match is true then delete row. Sheets("Sheet1").Cells(iCtr, 1).Delete xlShiftUp ' Increment counter to account for deleted row. iCtr = iCtr + 1 End If End If Next iCtr ' Go to next record. ActiveCell.Offset(1, 0).Select Loop End Sub
Ever
Edit: Added [vbcode][/vbcode] tags for clarity. - Hack





Reply With Quote