简体   繁体   English

使用 ActiveSheet.Range 时出现运行时错误 13“类型不匹配”

[英]Run Time Error 13 “Type Mismatch" when using ActiveSheet.Range

I am getting-我正进入(状态-

Run Time Error 13 “Type Mismatch"运行时错误 13“类型不匹配”

at this line of code.在这行代码。

ActiveSheet.Range(sheetRange).AutoFilter Field:=5, Criteria1:=(myAry), Operator:=xlFilterValues

myAry is an an array which contains string. myAry是一个包含字符串的数组。

sheetRange gets its value as following - sheetRange的值如下 -

lastRow = TotalRowsBeforeFilter()
    startRowNum = 1
    Let sheetRange = "A" & startRowNum & ":" & "E" & lastRow

Where am I doing wrong?我哪里做错了? I do not get this error on Excel 2016, but in Excel 2013 I am getting this error.我在 Excel 2016 上没有收到此错误,但在 Excel 2013 中我收到此错误。

I found the answer - I did not declare the Dim MyAry() as String instead I left it as Variant Type.我找到了答案 - 我没有将Dim MyAry() as String声明Dim MyAry() as String而是将其保留为 Variant Type。 When I declared MyAry as String, it worked.当我将 MyAry 声明为 String 时,它起作用了。 Strange though EXCEL 2016 does not have these issues.奇怪的是,虽然 EXCEL 2016 没有这些问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM