We are using Excel for reporting. As part of one of the reports the users have requested that a subset of the UsedRange of a worksheet is setup as a filterable area. i.e. were I to do it manually in Excel, I’d select the range, Data menu > Sort & Filter > Filter. This would use the top row as title and provide the availability to order/sort to the user.
I’ve done this previously in VBA in Developer mode in Excel, thus:
' filter on
If Not ActiveSheet.AutoFilterMode Then
ActiveSheet.UsedRange.AutoFilter
End If
I want to do exactly the same thing in C# using Excel Interop, but this code:
// make the data into a filtered area
if ((oAllDiffs.Count > 0) && (!_ws.AutoFilterMode))
_ws.Range["B8", $"T{8 + oAllDiffs.Count}"].AutoFilter();
generates the error:
{“_AutoFilter method of Range class failed”}
Not the most useful error message. How do I specify a range to enable sort/filter? To clarify, I don’t want to actually apply a sort/filter, just set the area up with filterable/sortable column titles.