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
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
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
 
Upvote 0
Solution
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
Thanks I will try shortly. I noticed it says helper column in C but I have data in C along with the rest of the sheet?
 
Upvote 0
Thanks I will try shortly. I noticed it says helper column in C but I have data in C along with the rest of the sheet?
Just change the temporary helper column to suit in this part:
VBA Code:
xHelp = "C"  'helper column
 
Upvote 0
Just change the temporary helper column to suit in this part:
VBA Code:
xHelp = "C"  'helper column
And it will sort the entire used sheet by column A first?
 
Upvote 0
No, it will sort the range from A to helper column by the helper column.
As I said in initial post I need the whole sheet sorted by column A first with cells with letters on the end in A first.
 
Upvote 0
If I put the helper column after the last column of data will that do the sort for whole sheet?
 
Upvote 0

Forum statistics

Threads
1,215,125
Messages
6,123,195
Members
449,090
Latest member
bes000

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