CodeGuru Forums - C-Sharp Programming https://forums.codeguru.com/ Post questions, answers, and comments about C#. en Wed, 21 Feb 2024 09:06:57 GMT vBulletin 60 https://forums.codeguru.com/images/misc/rss.png CodeGuru Forums - C-Sharp Programming https://forums.codeguru.com/ <![CDATA[[RESOLVED] C#.Net Excel Interop Autofilter Range]]> https://forums.codeguru.com/showthread.php?566233-RESOLVED-C-Net-Excel-Interop-Autofilter-Range&goto=newpost Tue, 30 Jan 2024 00:05:10 GMT =1/1/2024", Operator:=xlAnd, Criteria2:="<=1/31/2024" --------- Here is what I thought was the C# equivalent: Code: --------- excelRange.AutoFilter(Field: 6, Criteria1: ">=1/1/2024", Operator: Microsoft.Office.Interop.Excel.XlAutoFilterOperator.xlAnd, Criteria2: "<=1/25/2024"); --------- But I get the following runtime error in C#: *System.Runtime.InteropServices.COMException: '_AutoFilter method of Range class failed'*]]> I need the following filter to work in C#.

Here is the working Macro in Excel VBA:

Code:

ActiveSheet.Range("$A$1:$XFC$13214").AutoFilter Field:=6, Criteria1:= ">=1/1/2024", Operator:=xlAnd, Criteria2:="<=1/31/2024"
Here is what I thought was the C# equivalent:

Code:

excelRange.AutoFilter(Field: 6, Criteria1: ">=1/1/2024", Operator: Microsoft.Office.Interop.Excel.XlAutoFilterOperator.xlAnd, Criteria2: "<=1/25/2024");
But I get the following runtime error in C#:

System.Runtime.InteropServices.COMException: '_AutoFilter method of Range class failed' ]]>
C-Sharp Programming tim8w123 https://forums.codeguru.com/showthread.php?566233-RESOLVED-C-Net-Excel-Interop-Autofilter-Range