PDA

View Full Version : [SOLVED:] Trying to get a Macro to sort 4 digits



Larbec
11-04-2015, 11:07 PM
How can I sort the columns ABCDE and pull out all the ones that are similar and list them? If this is too difficult i can try and do them with a filter

Thanks

14703

nilem
11-05-2015, 01:05 AM
maybe so

Sub ertert()
With Range("A5").CurrentRegion
.Columns(.Columns.Count + 1).FormulaR1C1 = "=RC[-5]&RC[-4]&RC[-3]&RC[-2]"
With .CurrentRegion
.Sort Key1:=.Cells(1, .Columns.Count), Order1:=xlAscending
End With
.Columns(.Columns.Count + 1).ClearContents
End With
End Sub

Larbec
11-05-2015, 06:54 AM
maybe so

Sub ertert()
With Range("A5").CurrentRegion
.Columns(.Columns.Count + 1).FormulaR1C1 = "=RC[-5]&RC[-4]&RC[-3]&RC[-2]"
With .CurrentRegion
.Sort Key1:=.Cells(1, .Columns.Count), Order1:=xlAscending
End With
.Columns(.Columns.Count + 1).ClearContents
End With
End Sub

Thanks for the reply, the Macro works but it places all the digits in column E and then deletes itself. I really would like the data that is in E to be part of the 4 digits if possible too. Can the digits be displayed perhaps in column H or any place besides E? I tried removing the "ClearContents" in the last row and excel crashed so I guess that's not how to fix that part. I am learning and trying. Thanks again

Larbec
11-06-2015, 07:17 AM
maybe so

Sub ertert()
With Range("A5").CurrentRegion
.Columns(.Columns.Count + 1).FormulaR1C1 = "=RC[-5]&RC[-4]&RC[-3]&RC[-2]"
With .CurrentRegion
.Sort Key1:=.Cells(1, .Columns.Count), Order1:=xlAscending
End With
.Columns(.Columns.Count + 1).ClearContents
End With
End Sub

Ive tried to change different things with the Macro and still after it runs it deletes everything immediately and I can not seem to get the # in a column like E and Q hmmm

Larbec
11-06-2015, 09:47 PM
I figured it out,thanks. All I had to do was comment out that part