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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:02:18+00:00 2026-05-26T06:02:18+00:00

First time poster here :). I’m having the following trouble automating Excel 2010 from

  • 0

First time poster here :). I’m having the following trouble automating Excel 2010 from a WinForms C# application. My test table looks the following way:

Index    Value1  Value2
AAA        2       3   
AAA        3       4
AAA        3       8
BBB        2       2
BBB        5       6
BBB        3       5
CCC        1       2
CCC        2       2
DDD        2       5

I successfully open the workbook and load the sheet from my C# application. After that I run the following code:

        Excel.Range range = xlSheet.UsedRange;
        range.AutoFilter(1, "AAA", Excel.XlAutoFilterOperator.xlAnd, Type.Missing, true);
        Excel.Range filteredRange = range.SpecialCells(Excel.XlCellType.xlCellTypeVisible);

This works as expected, and filterRange now contains the first four rows of my test table (the column names and all the “AAA” rows). If, however, I try to use AutoFilter to get all the “BBB” rows, like this

        range.AutoFilter(1, "BBB", Excel.XlAutoFilterOperator.xlAnd, Type.Missing, true);
        Excel.Range filteredRange = range.SpecialCells(Excel.XlCellType.xlCellTypeVisible);

I end up with only the firs row of the table (column names) in the filteredRange Range. If I actually open the table in Excel I can see that it is correctly filtered (the “BBB” rows) are filtered, but somehow the Range.SpecialCells() method does not behave as expected and only returns the first row.
I’ve tried everything I can think of, but since I’m new to Excel automation, maybe I’m missing something, so I thought you guys might be able to help. The only thing that comes to my mind is that in the first case (“AAA”), all visible rows are consecutive – the column names are on row 1 and the “AAA” rows are 2, 3, and 4 respectively. In the second case, the names are on row 1 but the “BBB” rows are with index 5, 6 and 7, i.e. there is an “hole” in the table. Could this perhaps affect the SpecialCells() method?

Thanks in advance for any input you might have!

  • 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-26T06:02:18+00:00Added an answer on May 26, 2026 at 6:02 am

    OK, I solved my own problem, but I would like to share the solution because some other poor soul might struggle with the same problem someday. Basically, my first idea that the problem might be with the rows not being consecutive led me to the right answer. As long as all the filtered values are right under the first row in the table, the SpecialCells() method returns one single area, and so the filteredRange shows in its Value2 member all of the desired values (in the test case from above, all the “AAA”) rows. If, however, the filtered rows are further down in the table, as is the case with “BBB”, the SpecialCells() method returns multiple areas, in this case two – first area containing only the column names line, and the second area containing the three “BBB” rows. The solution is to iterate over all the areas in filteredRange and extract/manipulate the values from there:

            for (int areaId = 1; areaId <= filteredRange.Areas.Count; areaId++)
            {
                Excel.Range areaRange = filteredRange.Areas.get_Item(areaId);
                object[,] areaValues = areaRange.Value2;
                // Do something with the values here...
    

    So that’s it. I hope that this helps someone else someday…

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

Sidebar

Related Questions

First time poster here. A quick question about setting up a loop here. I
Long term lurker, first time poster here. I have written a class to model
first time poster - semi-newb to Rails. Here is my question. Suppose you have
I'm first time poster here trying to pick up some Python skills; please be
long time reader/first time poster here. So I've got a checkbox array that posted
Long time lurker, first time poster here. My question is: Using C# 2.0, is
first time poster here! I'm a Senior Computer Science Student and I'm currently developing
'Long time reader, first time poster' here. I'm in the process of making a
This is a pretty simple question; first time poster and long time looker. Here
first time poster and TDD adopter. :-) I'll be a bit verbose so please

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.