LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default DeleteDuplicateRows: problem with this macro


The macro DeleteDuplicateRows suggested on this sit
(http://www.cpearson.com/excel/deleting.htm) *seems* to have a
infinite loop error. Not too sure what the real glitch is but upo
running, my version of Excel (2002) goes into "hourglass mode
requiring Crt+Alt+Del.

The macro (and its description) is presented below.

Thx for any info you can provide!
-KH

To use, select a single-column range of cells, comprising the range o
rows from which duplicates are to be deleted, e.g., C2:C99. T
determine whether a row has duplicates, the values in the selecte
column are compared. Entire rows are not compared against one another.
Only the selected column is used for comparison. When duplicate value
are found in the active column, the first row remains, and al
subsequent rows are deleted.

Public Sub DeleteDuplicateRows()
'
' This macro deletes duplicate rows in the selection. Duplicates are
' counted in the COLUMN of the active cell.

Dim Col As Integer
Dim r As Long
Dim C As Range
Dim N As Long
Dim V As Variant
Dim Rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Col = ActiveCell.Column

If Selection.Rows.Count 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange.Rows
End If

N = 0
For r = Rng.Rows.Count To 1 Step -1
V = Rng.Cells(r, 1).Value
If Application.WorksheetFunction.CountIf(Rng.Columns( 1), V)
Then
Rng.Rows(r).EntireRow.Delete
N = N + 1
End If
Next r

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Su

--
KHashmi31
-----------------------------------------------------------------------
KHashmi316's Profile: http://www.excelforum.com/member.php...fo&userid=1043
View this thread: http://www.excelforum.com/showthread.php?threadid=37677

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Worksheet Functions 1 May 3rd 08 02:35 PM
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Discussion (Misc queries) 1 May 3rd 08 10:52 AM
Problem using Day() in a macro Marie Excel Worksheet Functions 2 December 14th 07 06:01 PM
Macro Problem carl Excel Worksheet Functions 1 August 21st 07 07:22 PM
Macro problem - help please Peter[_28_] Excel Programming 11 May 8th 05 12:58 AM


All times are GMT +1. The time now is 05:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"