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

I created this code to remove duplicates through the advanced filter,
but it`s very specific to a particular size and set of data, for example
columns F:F. How could it be adjusted so that it would work on all
types of data regardless of number of columns or rows?

Sub removeduplicates()

'highlight all data from which to remove duplicates
Sheets("Sheet1").Select
Cells.FindNext(After:=ActiveCell).Activate
Columns("F:F").Select
Selection.Clear
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Range("A1:E13").AdvancedFilter Action:=xlFilterInPlace, Unique:=True

'copy all visible lines in filter-in-place using a go to
and paste-special value to a new sheet
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets.Add
Sheets("Sheet2").Select
Sheets("Sheet2").Name = "file no duplicates"
Range("A1").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False

'in the new worksheet add a column, create a heading called "inventory"
and fill all the rows in the dataset with "yes" for this column
Range("E1").Select
Selection.End(xlDown).Select
Range("F6").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "xxx" 'I use a system of xxx to find and
fill to the last row of the dataset, but would appreciate knowing a
better way to do this
Range("F5").Select
Selection.End(xlUp).Select
ActiveCell.FormulaR1C1 = "inventory"
Range("F2").Select
ActiveCell.FormulaR1C1 = "yes"
Range("F2").Select
Selection.Copy
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste

'copy paste special values
Range("F6").Select
Application.CutCopyMode = False
Selection.ClearContents
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Range("A1").Select
Application.CutCopyMode = False

'delete the original file which has the duplicates
Sheets("Sheet1").Select
ActiveWindow.SelectedSheets.Delete
End Sub

Thank you.

Marina Madeleine


*** 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
Removing Duplicates Help Scott Excel Discussion (Misc queries) 6 May 5th 09 03:58 AM
Removing Duplicates Danielle Excel Worksheet Functions 5 March 10th 06 07:56 PM
removing duplicates robhargreaves Excel Discussion (Misc queries) 1 July 24th 05 12:35 AM
Removing Duplicates sat Excel Discussion (Misc queries) 5 June 18th 05 11:18 PM
Removing Duplicates sat Excel Worksheet Functions 1 June 18th 05 11:18 PM


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