Sort column macro

instanceoftime

Board Regular
Joined
Mar 23, 2011
Messages
103
I'm using the code below to format spreadsheets with various number of rows.
Unfortunately I have noticed my "sort" portion isn't always working correctly?

end result:

1999.99
1699.99
599.99
249.99
449.99
449.99
399.99
199.99
119.99
349.99
349.99
169.99
329.99
299.99
299.99
299.99
299.99
129.99
249.99
49.99
239.99

VBA Code:
Sub invoice()
'
' formating Macro
' control u
'
' Keyboard Shortcut: Ctrl+u
'
    Cells.Select  'left align
        With Selection
            .HorizontalAlignment = xlLeft
            .VerticalAlignment = xlBottom
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        
    Range("C:C,D:D,H:M").Select 'delete some columns
    Range("H1").Activate
    Selection.delete Shift:=xlToLeft
    
    Columns("C:C").Select 'resize column
    Selection.ColumnWidth = 45
    
[COLOR=rgb(226, 80, 65)]    Range("A2", Range("E" & Rows.Count).End(xlUp)).Sort [A2], xlDescending 'sort by column E[/COLOR]
    
    With Range("A2", Range("A" & Rows.Count).End(xlUp))   'truncate number in A
      .Value = Evaluate(Replace("If(@="""","""",right(@,3))", "@", .Address))
   End With

End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Will you always have data in the last row of col E?
 
Upvote 0
Try to change this line...
VBA Code:
Range("A2", Range("A" & Rows.Count).End(xlUp)).Sort [A2:A22], xlDescending 'sort by column
 
Upvote 0
Can you answer my question in post#2?
Also in what way isn't your code sorting properly?
 
Upvote 0

Forum statistics

Threads
1,224,747
Messages
6,180,719
Members
452,995
Latest member
isldboy

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