简体   繁体   中英

Excel Autofilter on cell separated by semicolon

I am trying to do exactly what is posted here , but not on double clicking a cell. I am trying to assign the event to a button on another sheet. Keeping getting an "object required" error and cant figure out why.

Dim Arr          'Array to SPLIT string
Dim i As Long    'Index to loop through Arr
Dim Filt         'Array to filter range
Sheet2.Cells.AutoFilter
Arr = Split(Sheet2.Range("g2"), ";")
ReDim Filt(LBound(Arr) To UBound(Arr))
    For i = LBound(Arr) To UBound(Arr)
        Filt(i) = CStr(Arr(i))
    Next i
Sheet2.Range("z5:z5000").AutoFilter 25, Filt, xlFilterValues

thanks to @BigBen, i was able to overcome the error. Here is the working piece of code should anyone else need help:

 Dim Arr          'Array to SPLIT string
 Dim i As Long    'Index to loop through Arr
 Dim Filt         'Array to filter range
 Arr = Split(Sheet2.Range("g2"), ";")
 ReDim Filt(LBound(Arr) To UBound(Arr))
 For i = LBound(Arr) To UBound(Arr)
    Filt(i) = CStr(Arr(i))
 Next i
 Sheet2.Range("z4").AutoFilter 25, Filt, xlFilterValues

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