Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default delete duplicates

HI all, I've got a spreadsheet where I have many duplicates rows. I've got a
cell in each row marked DUPLICATE and would like to run a macro to delete
them from the spreadsheet. Thanks.
--
delmac
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default delete duplicates

Hi Delmac,

One way:

Sub Tester()
Dim rng As Range
Dim sh As Worksheet
Dim lRow As Long
Dim i As Long
Const col As String = "D" '<<===== CHANGE

Set sh = ActiveWorkbook.Sheets("Sheet2") '<<===== CHANGE
Set rng = sh.Range("A2:D100") '<<===== CHANGE


lRow = rng.Rows(rng.Rows.Count).Row

With sh
For i = lRow To 2 Step -1
If .Rows(i).Cells(1, col).Value = "Duplicate" Then
.Rows(i).Delete
End If
Next
End With

End Sub

Change the value of col from "D" to the column containing "Duplicates".
Change the name of the workbook.worksheet to suit your requirements.

Change the value of range to suit. To operate on the whole sheet, replace:

Set rng = sh.Range("A2:D100")
with:
Set rng = sh.UsedRange

---
Regards,
Norman



"delmac" wrote in message
...
HI all, I've got a spreadsheet where I have many duplicates rows. I've got
a
cell in each row marked DUPLICATE and would like to run a macro to delete
them from the spreadsheet. Thanks.
--
delmac



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default delete duplicates

Hi Delamc,

Change:

If .Rows(i).Cells(1, col).Value = "Duplicate" Then


to

If .Rows(i).Cells(1, col).Value = "Duplicates" Then

to correct missing 's' in "Duplicates".


---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi Delmac,

One way:

Sub Tester()
Dim rng As Range
Dim sh As Worksheet
Dim lRow As Long
Dim i As Long
Const col As String = "D" '<<===== CHANGE

Set sh = ActiveWorkbook.Sheets("Sheet2") '<<===== CHANGE
Set rng = sh.Range("A2:D100") '<<===== CHANGE


lRow = rng.Rows(rng.Rows.Count).Row

With sh
For i = lRow To 2 Step -1
If .Rows(i).Cells(1, col).Value = "Duplicate" Then
.Rows(i).Delete
End If
Next
End With

End Sub

Change the value of col from "D" to the column containing "Duplicates".
Change the name of the workbook.worksheet to suit your requirements.

Change the value of range to suit. To operate on the whole sheet, replace:

Set rng = sh.Range("A2:D100")
with:
Set rng = sh.UsedRange

---
Regards,
Norman



"delmac" wrote in message
...
HI all, I've got a spreadsheet where I have many duplicates rows. I've
got a
cell in each row marked DUPLICATE and would like to run a macro to delete
them from the spreadsheet. Thanks.
--
delmac





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
delete duplicates DogmaDot Excel Discussion (Misc queries) 1 March 18th 10 10:18 PM
Delete duplicates Angie M. Excel Worksheet Functions 4 February 4th 10 03:56 AM
Delete duplicates? WH99 Excel Discussion (Misc queries) 2 April 16th 08 04:41 PM
Delete duplicates? kk Excel Discussion (Misc queries) 2 March 14th 08 02:22 PM
Delete Duplicates Lauren New Users to Excel 4 April 11th 06 05:46 AM


All times are GMT +1. The time now is 02:17 AM.

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

About Us

"It's about Microsoft Excel"