AutoFilter - To filter data between two dates

syed

Member
Hi,

I am trying to apply autofilter to one of my date column inorder filter data between two dates. I am using code stage to achieve this, below is the code I am using

GetWorkbook(handle,Nothing).Worksheets(sheetName).Activate
GetWorkbook(handle,Nothing).ActiveSheet.Range("A3:CN3000").AutoFilter(Field:=38, Criteria1:=">=1/1/2014", Operator:="xlAnd", Criteria2:="<=12/31/2016")

I am getting "Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))" Exception. I am attaching screenshot of the code stage.

Kindly help me what mistake I am making.

Note:

I have filter successfully using macros with below codes:
Range("A3:CN3000").AutoFilter
ActiveSheet.Range("$A$1:$C$20").AutoFilter Field:=38, Criteria1:=">=1/1/2014", Operator:=xlAnd, Criteria2:="<=12/31/2016"

Same thing when I tried to achieve through code stage I am getting above mentioned exception.
 

Attachments

  • 1571841465650.png
    69.2 KB · Views: 13

tomahawk1

New Member
xlAnd is a constant (cannot be "xlAnd") which only Office Library in Excel recognizes. Therefore replace word for number: Operator:=1
I also cannot see on picture if you have sheetname declared in code stage as an input, if not, then add this as first line: Dim sheetname as String = "Sheet1" (where instead of Sheet1 you put actual name of sheet)
 

syed

Member
xlAnd is a constant (cannot be "xlAnd") which only Office Library in Excel recognizes. Therefore replace word for number: Operator:=1
I also cannot see on picture if you have sheetname declared in code stage as an input, if not, then add this as first line: Dim sheetname as String = "Sheet1" (where instead of Sheet1 you put actual name of sheet)


Thanks, Operator is the problem. After changing it to 1 it works fine.
 
Top