How to Get Excel 2007 "Sort By" ??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ronnysaid
    New Member
    • Jan 2009
    • 7

    How to Get Excel 2007 "Sort By" ??

    Hello,

    Is there a way to get Excel 2007 "sort by" value from a cell range??

    to be more clear, if column header is country and you sorted cell range (A1,A10) by country, is there a way to get "country" using C#???

    Thanks.
  • SammyB
    Recognized Expert Contributor
    • Mar 2007
    • 807

    #2
    It is frustrating that the sort dialog, xlDialogSort, knows this information, but mere mortals do not have access to it. There are three ugly ways that I can think of:
    (1) briefly show the dialog and use API calls to retrieve the text from the dialog, but speaking from experience, you will get gray hairs doing this and the users will wonder what flashed up on the screen.
    (2) examine the columns of data in code and determine which one is sorted, but if the data is already sorted, this will not get the users last sort operation.
    (3) if you are only doing the sort in code, keep track of it yourself. You can even stash this information in a custom doc property, so you can retrieve it when opening a workbook.

    Comment

    • ronnysaid
      New Member
      • Jan 2009
      • 7

      #3
      SammyB , thank you for your answer, i posted this question on many forums, all started guessing, this the only answer i needed, thank you very very much for your help.

      According to the method i followed earlier,the way is to examine the data itself by getting the sort address from user last sort operation, i think this workaround did it for me but i thought there is an easier way to do it, i hate microsoft for not supporting this property.

      thank you again, appreciated.

      Comment

      Working...