Results 1 to 10 of 10

Thread: Frozen Macro (Loops)

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2003
    Posts
    27

    Frozen Macro (Loops)

    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:
    1. Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    2.     Dim iListCount As String
    3.     Dim iCtr As Integer
    4.  
    5.   ' Get count of records to search through.
    6.       iListCount = Sheets("Sheet1").Range("A1:A100").Rows.Count
    7.       Sheets("Sheet1").Range("A1").Select
    8.      ' Loop until end of records.
    9.         Do Until ActiveCell = ""
    10.           ' Loop through records.
    11.             For iCtr = 1 To iListCount
    12.          ' Don't compare against yourself.
    13.          ' To specify a different column, change 1 to the column number.
    14.            If ActiveCell.Row <> Sheets("Sheet1").Cells(iCtr, 1).Row Then
    15.          ' Do comparison of next record.
    16.             If ActiveCell.Value = Sheets("Sheet1").Cells(iCtr, 1).Value Then
    17.             ' If match is true then delete row.
    18.                  Sheets("Sheet1").Cells(iCtr, 1).Delete xlShiftUp
    19.                ' Increment counter to account for deleted row.
    20.                iCtr = iCtr + 1
    21.          End If
    22.       End If
    23.    Next iCtr
    24.    ' Go to next record.
    25.    ActiveCell.Offset(1, 0).Select
    26.  Loop
    27. End Sub

    Ever


    Edit: Added [vbcode][/vbcode] tags for clarity. - Hack
    Last edited by si_the_geek; Sep 27th, 2005 at 10:17 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width