Sort By Column A When Letter On End

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,748
Office Version
  1. 365
Platform
  1. Windows
I have column A with data of varying lengths. I need a macro please that will sort the entire sheet by column A when there is a letter on the end like below first. I have highlighted for clarity once sort is done. Thanks

Before
AUA316D 5005A
AUA316D 5005B
AUA320D 1032
AUA320D 1034
AUA320D 2001B
AUA320D 2030
AUA320D 2034


After
AUA316D 5005A
AUA316D 5005B
AUA320D 2001B
AUA320D 1032
AUA320D 1034
AUA320D 2030
AUA320D 2034
 
Try this:
VBA Code:
Sub try_1()
Dim i As Long, n As Long
Dim va, vb
Dim xHelp As String

xHelp = "C"  'helper column
n = Range("A" & Rows.Count).End(xlUp).Row
Columns(xHelp).Clear
va = Range("A1:A" & n)
ReDim vb(1 To n, 1 To 1)

For i = 1 To UBound(va, 1)
    If Right(va(i, 1), 1) Like "[A-Z]" Then vb(i, 1) = 1
Next

Cells(1, xHelp).Resize(n, 1) = vb
Range(Cells(1, "A"), Cells(n, xHelp)).Sort Key1:=Cells(1, xHelp), Order1:=xlAscending, Header:=xlYes
Columns(xHelp).Clear
End Sub
That works, much obliged squire.
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
What do you do when it falls so far down the list and you still haven't got a solution?
If you go 24 hours without any new replies, you can "bump" the thread back to the top by replying to it yourself again.
 
Upvote 0

Forum statistics

Threads
1,215,129
Messages
6,123,216
Members
449,091
Latest member
jeremy_bp001

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top