View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
RB Smissaert RB Smissaert is offline
external usenet poster
 
Posts: 2,452
Default Filter unique in range, only keep visible

Trying to make some code that filters the unique rows in a range, but only
leaves the visible row, making it just as a normal range. So, no blue row
numbers and continuous row numbering without gaps.
Something like this will do it, but I think there must be a shorter more
elegant way:

Sub test()
FilterUniqueInRange ActiveSheet, ActiveWindow.RangeSelection
End Sub


Sub FilterUniqueInRange(sh As Worksheet, rng As Range)

Dim arr
Dim shTemp

sh.Activate
rng.AdvancedFilter Action:=xlFilterInPlace, Unique:=True
ActiveWindow.RangeSelection.Copy

Set shTemp =
ActiveWorkbook.Sheets.Add(after:=Worksheets(Worksh eets.Count))
shTemp.Name = "tempPaste"
shTemp.Activate
ActiveSheet.Paste
Application.CutCopyMode = False

With sh
.ShowAllData
.Cells.Clear
End With

ActiveWindow.RangeSelection.Copy

sh.Activate
Cells(1).Select
ActiveSheet.Paste
Application.CutCopyMode = False

Application.DisplayAlerts = False
shTemp.Delete
Application.DisplayAlerts = True

End Sub


RBS