ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro Button to Sort Columns - Troubleshooting ideas? (https://www.excelbanter.com/excel-programming/429253-macro-button-sort-columns-troubleshooting-ideas.html)

munchkin

Macro Button to Sort Columns - Troubleshooting ideas?
 
My worksheets has 500 rows / 8 columns & there is a Header Row. Column A =
acct. number, Column B = Cutomer Name, Column C = Department, Column D =
Manager. I created marcos that sort specific columns with the click of a
button. When you sort by C or D, it works fine, but if you then try to
resort by account number Row 4 is excluded from the sort - even though my
macro includes it (see below) Any idea why?

Range("A4").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Sort Key1:=Range("A4"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("A4").Select



Don Guillett

Macro Button to Sort Columns - Troubleshooting ideas?
 
Without seeing your data, try one of these

Sub sortrang()
Range(Range("a4"), Range("a4").End(xlDown).End(xlToRight)) _
..Sort Key1:=Range("A4"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub

Sub sortusedrange()
Range("a4").CurrentRegion _
..Sort Key1:=Range("A4"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Munchkin" wrote in message
...
My worksheets has 500 rows / 8 columns & there is a Header Row. Column A
=
acct. number, Column B = Cutomer Name, Column C = Department, Column D =
Manager. I created marcos that sort specific columns with the click of a
button. When you sort by C or D, it works fine, but if you then try to
resort by account number Row 4 is excluded from the sort - even though my
macro includes it (see below) Any idea why?

Range("A4").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Sort Key1:=Range("A4"), Order1:=xlAscending, Header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("A4").Select





All times are GMT +1. The time now is 12:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com