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 7549285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:54:49+00:00 2026-05-30T09:54:49+00:00

In VSTO 2010 in Excel, the Range.Sort method doesn’t seem to work for me.

  • 0

In VSTO 2010 in Excel, the Range.Sort method doesn’t seem to work for me. Here’s my example code. It puts the numbers 1 to 20 in reverse order in column A, and then unsuccessfully tries to sort them.

Worksheet sheet = Globals.ThisAddIn.Application.ActiveSheet;
Enumerable.Range(1, 20).ToList().ForEach(i => sheet.Cells[21 - i, 1] = i);
sheet.Columns[1].Sort();

According to the documentation, the Sort with no arguments will sort in ascending order. Just in case I tried specifying Order1: XlSortOrder.xlAscending.

I also tried

sheet.Columns[1].Select().Sort();

to select the column first, but this didn’t work either.

How can I sort a Range of cells?

  • 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-05-30T09:54:51+00:00Added an answer on May 30, 2026 at 9:54 am

    I tried your approach in VBA and receved the error “sort method of range class failed”.

    I resolved that by passing the range as the “Key1” argument of the method. Seems redundant, but it works. Here’s your sample code with the same fix applied:

    Worksheet sheet = Globals.ThisAddIn.Application.ActiveSheet;
    Enumerable.Range(1, 20).ToList().ForEach(i => sheet.Cells[21 - i, 1] = i);
    sheet.Columns[1].Sort(sheet.Columns[1]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an Excel 2010 VSTO solution (doing code-behind for an Excel workbook
Does VSTO 2008 work for Office 2010 or will it only be VSTO 2010?
How does Excel VSTO Work? If I create an Excel Workbook solution in Visual
In a VSTO Excel addin the code: Dim XMLDoc As XElement = XElement.Load(XMLFile1.xml) generates
i am using vsto, to work with excel-2007... let's consider i have a matrix
I've got a VSTO 3.0 Word Addin. Around here, they do all work off
When I doubleclick to install a VSTO plugin for Excel 2010 I get a
I am just starting with Excel 2010 Add-in with VSTO and is quickly stumped
I am working on a VSTO project using excel 2010 and visual studio 2010.
I use VSTO Excel template based solutions frequently. One of the things I like

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.