Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8361125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:37:51+00:00 2026-06-09T11:37:51+00:00

I am trying to sort a worksheet by the first column in excel using

  • 0

I am trying to sort a worksheet by the first column in excel using INTEROP.

I just want a simple sort of the entire range by the first column. I am doing the following:

valueRange.Sort(valueRange.Columns[7, Type.Missing], Excel.XlSortOrder.xlAscending, valueRange.Columns[7, Type.Missing],
                Type.Missing, Excel.XlSortOrder.xlAscending, Type.Missing, Excel.XlSortOrder.xlAscending, 
                Excel.XlYesNoGuess.xlNo, Type.Missing, Type.Missing, Excel.XlSortOrientation.xlSortColumns, 
                Excel.XlSortMethod.xlPinYin, Excel.XlSortDataOption.xlSortNormal, 
                Excel.XlSortDataOption.xlSortNormal, Excel.XlSortDataOption.xlSortNormal);

But getting errors. I am unable to find proper documentation on how to do this sorting.

Could someone please give me a working example of a simple sort of a specified range by a specific column?

as per documentation I tried to do this:

valueRange.Sort(valueRange.Columns[7, Type.Missing],
                        Excel.XlSortOrder.xlAscending,
                        Type.Missing,
                        Type.Missing,
                        Excel.XlSortOrder.xlAscending,
                        Type.Missing,
                        Excel.XlSortOrder.xlAscending,
                        Excel.XlYesNoGuess.xlNo,
                        Type.Missing,
                        Type.Missing,
                        Excel.XlSortOrientation.xlSortColumns,
                        Excel.XlSortMethod.xlStroke,
                        Excel.XlSortDataOption.xlSortNormal,
                        Excel.XlSortDataOption.xlSortNormal,
                        Excel.XlSortDataOption.xlSortNormal);

However right now I am getting the errors:

{“The sort reference is not valid. Make sure that it’s within the data you want to sort, and the first Sort By box isn’t the same or blank.”}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:37:52+00:00Added an answer on June 9, 2026 at 11:37 am

    In order to sort a range by a single column in that range, you can do something like the following (if you are using VS 2010 and above with the “dynamic” keyword):

    dynamic allDataRange = worksheet.UsedRange;
    allDataRange.Sort(allDataRange.Columns[7], Excel.XlSortOrder.xlDescending);
    

    In my example, I had a spreadsheet with 10 or so columns, and I wanted to sort the entire spreadsheet by the 7th column, in descending order.

    I was helped by the above answer, but when I tried Code4Life’s snippet:

    dynamic valueRange = GetTheRange();
    valueRange.Columns.get_Item(1)).Sort(valueRange.Columns[1]);
    

    it only sorted the first column of the range. The OP asked for sorting an entire range by one column, not sorting one column in a range. So after a little trial and error I got my above simplified code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to sort column Foo that has one Bar . Currently, I'm using
Trying to sort the following TEAM_TOTAL Column Desc MATCHID TEAM_TOTAL ---------- ----------------- 573 Total
I am trying to sort a two-dimensional array by a timestamp column Descending. This
I am trying to sort a Vector list using the Java Collections frameworks. This
I am trying to sort an array of integers in MIPS using bubble sort
I am trying to sort a list of records that have been created using
I am trying to sort a ListView which also has a DateTime column. This
Trying to sort an array by writing my own sort method using recursion (Pine's
I'm setting up a new store using 1.4.1 I'm trying sort the products in
I am trying to sort a multidimensional JSON array (called jsontest here) using JQuery

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.