none
Adding Filters to Columns in Excel RRS feed

  • Question

  • Hi,

    I am generating a spreadsheet using C# which contains blank rows.

    I initially generated the spreadsheet OK and can get filters on all the columns but the lists stop at the first blank line.

    So tried defining the range of the data for each column ie>

        Excel.Range elementRange = _xlWorkSheet.get_Range("C2", "C90");

        elementRange.AutoFilter(1, _misValue, Excel.XlAutoFilterOperator.xlAnd, _misValue, true);

    This will work for any column but if i try to add filters to more than 1 column it only works on the first column setup.

    I have spent a good few hours on the web trying different solutions it still amounts to the same thing.

    So can anyone point out my obvious mistake / misunderstanding.

    Thanks

    Wednesday, October 21, 2015 3:23 PM

Answers

  • ​>>>This will work for any column but if i try to add filters to more than 1 column it only works on the first column setup.

    According to your description, I have tried to reproduce this issue, unfortunately, I am not able to reproduce.

    If I do not misunderstand, maybe you want to achieve like this:

     

    You could select Range including more than one column, then use Range.AutoFilter method, please refer to below code:

    Range("A1:B4").Select
    
    Selection.AutoFilter
    

    If I misunderstand, I suggest that you could manually add filters to more than one column with "Record Macro". If you could success achieving your requirement, you could refer to VBA codes, then change them into C# codes.

    For more information, click here to refer about Range.AutoFilter Method (Excel)

    Thursday, October 22, 2015 9:58 AM