Unexpected behavior in Excel when sorting

  • Thread starter Thread starter DaveC426913
  • Start date Start date
  • Tags Tags
    Excel Sorting
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
9 replies · 3K views
DaveC426913
Gold Member
2025 Award
Messages
24,603
Reaction score
8,940
TL;DR
When I try to sort a spreadsheet, it ignores the first row (not a header.)
I'm trying to sort this sheet in Excel. I want to sort it on Column D.

1698778735967.png


I select the entire page by clicking the black arrow in the upper left corner:

1698778755418.png


Now I Data > Sort which brings up a dialogue where I specify the column I want to sort by :

1698778780227.png


(I can already tell there may be a problem - the first row has become deselected. This was not my doing. It happens every time):

1698778792033.png


An indeed, the sheet is sorted on column D, except the first row:

1698778811534.png


It doesn't matter how many times I do this - it's not a slip of the thumb - it always happens on this sheet. (And I have encountered this before, so it's not an artefact of this sheet only).

It's not a matter of data type of something life that. It happens on any other column I try to sort on:This is sorting on column A:

1698778859779.png


This is sorting on column F:

1698778872229.png


The only thing that worked was to cut and paste the row from the top to the bottom:

1698778913531.png


And now it sorts OK:

1698778939998.png
What am I doing wrong?
 
Physics news on Phys.org
[ UPDATE ]
Man there is nothing so effective for trouble-shooting as writing up the problem unambiguously in preparation for asking for help... :sorry:

When I went to update the veeery last screenshot, I saw this:
1698779437151.png
 
Reply
  • Like
  • Haha
Likes   Reactions: jrmichler, berkeman, jedishrfu and 4 others
jedishrfu said:
Is that why your first post has all strikeout text?
Yes. Save readers the time of reading through it all, only to discover I'd found the answer.

And I figured, since I'd already made the entire post, deleting it would only deprive some future readers in the same boat from reaping the benefit of my trials and tribulations.
 
Reply
  • Like
Likes   Reactions: jedishrfu, Baluncore and berkeman
DaveC426913 said:
Man there is nothing so effective for trouble-shooting as writing up the problem unambiguously in preparation for asking for help...
Also for solving engineering problems....
 
Probably the most important advantage of a forum like PF, is that the OP needs to work out what question to ask. After reading threads like this, we all become humbler.

“The only interesting answers are those which destroy the question”. —Susan Sontag
 
Reply
  • Like
Likes   Reactions: DaveC426913
Dave, I also had to track this down one time. Obvious once you know about the option but MS Office software has SO many options that it's hard to keep track of them all.
 
phinds said:
Dave, I also had to track this down one time. Obvious once you know about the option but MS Office software has SO many options that it's hard to keep track of them all.
Indeed. The gotcha in this case was that it the first row's behavior hinted at being a header, but the only way to define a row to behave as a header is to "freeze" it. Which of course, I did not do.

Knowing that's how Excel "handles" headers, one would not think to go looking for an option on a dialogue that said, effectively "Don't become a header, just pretend to act like one - for the moment - and then go back to being a regular row, like nothing ever happened." :mad:
 
Reply
  • Informative
  • Like
Likes   Reactions: phinds and Bystander
DaveC426913 said:
[ UPDATE ]
Man there is nothing so effective for trouble-shooting as writing up the problem unambiguously in preparation for asking for help... :sorry:

When I went to update the veeery last screenshot, I saw this:View attachment 334595
I wrote this in my form code:
'TARGET WITHIN RANGE - RUN JOB
ActiveCell.Select
Selection.Sort Key1:=ActiveCell, Order1:=xlAscending, _
HEADER:=xlYes, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
GoTo FINISHED
 
Gifovaco said:
I wrote this in my form code:
'TARGET WITHIN RANGE - RUN JOB
ActiveCell.Select
Selection.Sort Key1:=ActiveCell, Order1:=xlAscending, _
HEADER:=xlYes, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
GoTo FINISHED
Excel loves to think for you. In order to totally control it I run a script recursively that deletes ALL formatting. THEN I wrie what I want.... Excel is a 'trick' monster