ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Sorting a Selection (https://www.excelbanter.com/excel-discussion-misc-queries/146685-sorting-selection.html)

MarkCA

Sorting a Selection
 
I use a particular spreadsheet everyday, and sort the data in three columns
of the worksheet many times (there is also other data that I do not sort). I
don't have a header row. Until recently, the spreadsheet seemed to know how
I wanted to sort, and the 'sort by' box always appeared with the sort by
defaulting to my previous criteria, seemingly remembering how I had sorted it
last time.

Recently something has happened, and every time I go to sort, first the
dialogue box comes up showing a header row, and when I change it to show no
header row, EACH time it defaults to "sort by column A", even though I always
sort this worksheet by columns B, C, and D. So now I have extra steps to
direct the sheet to sort by B-C-D everytime I want to sort.

Is there a setting somewhere, or was I just lucky before?


mikerickson

If you select your range and call this routine, the sort dialog box will appear with your prefered settings as the default. You can change the settings before you choose to sort.
Code:

Sub SortWithDefaults()
Dim xval As Variant
xval = Application.Dialogs(xlDialogSort).Show(xlTopToBottom, _
            Range("b1"), xlAscending, _
            Range("c1"), xlAscending, _
            Range("d1"), xlAscending, xlYes, 1, False)

End Sub

Quote:

Originally Posted by MarkCA (Post 509991)
I use a particular spreadsheet everyday, and sort the data in three columns
of the worksheet many times (there is also other data that I do not sort). I
don't have a header row. Until recently, the spreadsheet seemed to know how
I wanted to sort, and the 'sort by' box always appeared with the sort by
defaulting to my previous criteria, seemingly remembering how I had sorted it
last time.

Recently something has happened, and every time I go to sort, first the
dialogue box comes up showing a header row, and when I change it to show no
header row, EACH time it defaults to "sort by column A", even though I always
sort this worksheet by columns B, C, and D. So now I have extra steps to
direct the sheet to sort by B-C-D everytime I want to sort.

Is there a setting somewhere, or was I just lucky before?


MarkCA

Sorting a Selection
 
Thanks - now I'm really going to show my ignorance. What do I do with the
code you provided? Is it a macro?

The problem self corrected briefly when I changed the first item in row A to
something else (it had been in the A1 position for a long time). But after a
while it went back to default sort with a header row, which I never do with
this sheet.

Seems like it has a mind of its own.

Thanks again.


"mikerickson" wrote:


If you select your range and call this routine, the sort dialog box will
appear with your prefered settings as the default. You can change the
settings before you choose to sort.

Code:
--------------------
Sub SortWithDefaults()
Dim xval As Variant
xval = Application.Dialogs(xlDialogSort).Show(xlTopToBott om, _
Range("b1"), xlAscending, _
Range("c1"), xlAscending, _
Range("d1"), xlAscending, xlYes, 1, False)

End Sub
--------------------


MarkCA;509991 Wrote:
I use a particular spreadsheet everyday, and sort the data in three
columns
of the worksheet many times (there is also other data that I do not
sort). I
don't have a header row. Until recently, the spreadsheet seemed to
know how
I wanted to sort, and the 'sort by' box always appeared with the sort
by
defaulting to my previous criteria, seemingly remembering how I had
sorted it
last time.

Recently something has happened, and every time I go to sort, first the

dialogue box comes up showing a header row, and when I change it to
show no
header row, EACH time it defaults to "sort by column A", even though I
always
sort this worksheet by columns B, C, and D. So now I have extra steps
to
direct the sheet to sort by B-C-D everytime I want to sort.

Is there a setting somewhere, or was I just lucky before?





--
mikerickson


mikerickson

It doesn't have a mind of its own, it just thinks you want it to be helpful rather than consistant.

Yes that is a macro.
To put it in your workbook, goto Tools-Macro-Visual Basic Editior
Insert a Module (not a class Module)
Copy the code from your web browser to the window.
Close the VB editor.

Use Excel's help system (keyword:=macro) to assign the routine to a button.




Quote:

Originally Posted by MarkCA (Post 514012)
Thanks - now I'm really going to show my ignorance. What do I do with the
code you provided? Is it a macro?

The problem self corrected briefly when I changed the first item in row A to
something else (it had been in the A1 position for a long time). But after a
while it went back to default sort with a header row, which I never do with
this sheet.

Seems like it has a mind of its own.

Thanks again.


"mikerickson" wrote:


If you select your range and call this routine, the sort dialog box will
appear with your prefered settings as the default. You can change the
settings before you choose to sort.

Code:
--------------------
Sub SortWithDefaults()
Dim xval As Variant
xval = Application.Dialogs(xlDialogSort).Show(xlTopToBott om, _
Range("b1"), xlAscending, _
Range("c1"), xlAscending, _
Range("d1"), xlAscending, xlYes, 1, False)

End Sub
--------------------


MarkCA;509991 Wrote:
I use a particular spreadsheet everyday, and sort the data in three
columns
of the worksheet many times (there is also other data that I do not
sort). I
don't have a header row. Until recently, the spreadsheet seemed to
know how
I wanted to sort, and the 'sort by' box always appeared with the sort
by
defaulting to my previous criteria, seemingly remembering how I had
sorted it
last time.

Recently something has happened, and every time I go to sort, first the

dialogue box comes up showing a header row, and when I change it to
show no
header row, EACH time it defaults to "sort by column A", even though I
always
sort this worksheet by columns B, C, and D. So now I have extra steps
to
direct the sheet to sort by B-C-D everytime I want to sort.

Is there a setting somewhere, or was I just lucky before?





--
mikerickson



All times are GMT +1. The time now is 07:11 PM.

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