简体   繁体   中英

VBA Excel - overflow error on range select

I got the following code, now when I filter my results with the following and it returns no results I get an overflow error. But I don't see why. I figured it would be the fact I try to select a bad range. So I tried checking if the first cell with a value is empty or not. But that doesn't seem to help at the moment.

If Range("A2") <> "" Then
    iCtr = Range("A2", Range("A2").End(xlDown)).Count + 1
    ActiveSheet.Range("$A$1:$AB" & iCtr).AutoFilter Field:=8, Criteria1:="=1100" _
    , Operator:=xlOr, Criteria2:="=1110"
End If

So anyone has any idea how to solve this or what the issue is?

Define

Dim iCtr AS Long

as that would safely let it accept range RowCount s of any size.

From information above, it is highly suspect iCtr as Integer that caused the problem. The maximum Integer is 32767, so it cannot hold large number. You can define it as Long to avoid the overflow problem.

Dim iCtr As Long

As a Long, the maximum value will goes up to 2147483647.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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