sirenetta1
Board Regular
- Joined
- Feb 11, 2004
- Messages
- 169
Hello,
Tom Urtis posted and helped me solve my problem on how to sort numbers in cells by using this macro (thanks Tom!):
This worked really well. My question is, is there a way for the macro to also delete duplicate numbers after sorting?
Example:
BEFORE SORTING:
1, 4, 3, 3, 2, 1, 6
CLICK MACRO:
1, 2, 3, 4, 5, 6
Thanks!
Tom Urtis posted and helped me solve my problem on how to sort numbers in cells by using this macro (thanks Tom!):
Code:
Sub Test2()
With Application
.ScreenUpdating = False
.DisplayAlerts = False
Dim asn$, aca$, straca$, cell As Range, CommaCell As Range
asn = ActiveSheet.Name
For Each cell In Selection
If InStr(cell, ",") > 0 Then
aca = cell.Address
straca = Range(aca).Value
Sheets.Add
Range("A1").Value = straca
Range("A1").TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
ConsecutiveDelimiter:=True, Tab:=True, Comma:=True, Space:=True, _
FieldInfo:=Array(Array(1, 1))
Range("A1").Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight
For Each CommaCell In Rows(1).SpecialCells(2)
Range("A2").Value = Range("A2").Value & CommaCell.Value & ", "
Next CommaCell
Range("A3").Formula = "=LEFT(R2C1,LEN(R2C1)-2)"
Sheets(asn).Range(aca).Value = Range("A3").Value
ActiveSheet.Delete
End If
Next cell
.Goto ThisWorkbook.Worksheets(asn).Range("A1"), True
.DisplayAlerts = True
.ScreenUpdating = True
End With
End Sub
This worked really well. My question is, is there a way for the macro to also delete duplicate numbers after sorting?
Example:
BEFORE SORTING:
1, 4, 3, 3, 2, 1, 6
CLICK MACRO:
1, 2, 3, 4, 5, 6
Thanks!