Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default code to remove row duplications

I`d like to use this code to remove all duplicate rows in a dataset and
then to run it in a number of worksheets with datasets of varying size
(rows and columns) where the range is changing. I`ve used the advanced
filter (unique) option. But the code is not working. Anyone know the
right code for this?

sheets ("sheet1").select
range("A1").CurrentRegion.select.advancedfilter Action:=xlfiltercopy,_
copytorange:=range(???), Unique:=true

David Shapiro



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default code to remove row duplications

Hi
check
http://cpearson.com/excel/deleting.h...eDuplicateRows

-----Original Message-----
I`d like to use this code to remove all duplicate rows in

a dataset and
then to run it in a number of worksheets with datasets of

varying size
(rows and columns) where the range is changing. I`ve

used the advanced
filter (unique) option. But the code is not working.

Anyone know the
right code for this?

sheets ("sheet1").select
range("A1").CurrentRegion.select.advancedfilter

Action:=xlfiltercopy,_
copytorange:=range(???), Unique:=true

David Shapiro



*** Sent via Developersdex http://www.developersdex.com

***
Don't just participate in USENET...get rewarded for it!
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default code to remove row duplications

code to remove row duplications
From: david shapiro
Date Posted: 9/20/2004 8:03:00 AM

Frank, sorry actually had intended to send this to you. Any ideas on
the below?

Dave


Norman,
Thanks for the suggestion, it`s good to know about that page. I checked
this page, and I`d like to put this code except that I`d like to delete
duplicate rows which are identical.

I think this code (copied below) duplicates on the basis of selected
columns. Is there some way to alter this code so that it deletes
duplicate rows?

David

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) 1 Then
Rng.Rows(r).EntireRow.Delete
N = N + 1
End If
Next r

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub





*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default code to remove row duplications

Hi David,

I`ve used the advanced filter (unique) option.
But the code is not working


Your problem may reside in the fact that, in order to extract the filter
data to another sheet, it is necessary to set up the filter operation from
the destination sheet.

See the section: Extract Data to Another Worksheet

on Debra Dalgleish's Advanced Filter page

http://www.contextures.com/xladvfilter01.html

---
Regards,
Norman



"david shapiro" wrote in message
...
I`d like to use this code to remove all duplicate rows in a dataset and
then to run it in a number of worksheets with datasets of varying size
(rows and columns) where the range is changing. I`ve used the advanced
filter (unique) option. But the code is not working. Anyone know the
right code for this?

sheets ("sheet1").select
range("A1").CurrentRegion.select.advancedfilter Action:=xlfiltercopy,_
copytorange:=range(???), Unique:=true

David Shapiro



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default code to remove row duplications

Norman,

Thanks for the suggestion, it`s good to know about that page. I checked
this page, and I`d like to put this code except that I`d like to delete
duplicate rows which are identical.

I think this code (copied below) duplicates on the basis of selected
columns. Is there some way to alter this code so that it deletes
duplicate rows?

David

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) 1 Then
Rng.Rows(r).EntireRow.Delete
N = N + 1
End If
Next r

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub






*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default code to remove row duplications

Hi David,

Your code, which was originally supplied by Chip Pearson, does delete rows.
It uses the active column to determine duplication.

---
Regards,
Norman



"david shapiro" wrote in message
...
Norman,

Thanks for the suggestion, it`s good to know about that page. I checked
this page, and I`d like to put this code except that I`d like to delete
duplicate rows which are identical.

I think this code (copied below) duplicates on the basis of selected
columns. Is there some way to alter this code so that it deletes
duplicate rows?

David

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) 1 Then
Rng.Rows(r).EntireRow.Delete
N = N + 1
End If
Next r

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub






*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Reply
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
Deleting Duplications Ray_V Excel Discussion (Misc queries) 3 August 10th 06 09:45 PM
remove duplications Vass Excel Discussion (Misc queries) 1 July 28th 05 04:32 PM
VBA Code to remove VBA Cory Thomas[_6_] Excel Programming 3 June 9th 04 04:06 PM
Use VB code to remove code in sheet1 WashoeJeff Excel Programming 4 January 25th 04 12:23 AM
Remove VBA code Michi[_2_] Excel Programming 3 January 21st 04 04:18 PM


All times are GMT +1. The time now is 09:34 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"