回復 11#yagami12th
For Each E In Sheets '工作表1,工作表2,工作表3
If E.FilterMode Then E.AutoFilterMode = False '有篩選時 取消[篩選]
Debug.Print E.Name '看錯誤是那一工作表
For i = E.[A2] To E.[A2].End(xlDown) '日期[A2]到 To E.[A2].End(xlDown) 必須是日期
E.AutoFilterMode = False
回復 17#yagami12th
真是丈二金剛!!
Dim E As Worksheet, i As Date, M As Variant, AR(), C As Variant 刪掉試試看
成 Dim E As Worksheet, i , M As Variant, AR(), C As Variant
請再上傳你測試的檔案 看看作者: yagami12th 時間: 2012-1-6 13:40
擷取的說明:
http://www.pcreview.co.uk/forums/excel-can-use-variable-autofilter-vba-t3748818.html
======================
This is from "Excel 2002 VBA Programmer's Reference"
Written by John Green, Stephen Bullen, Rob Bovey and Robert Rosenberg
http://www.oaltd.co.uk:80/ExcelProgR...rogRefCh22.htm
Search for "Range.AutoFilter" and you'll see this note:
Range.AutoFilter
The AutoFilter method of a Range object is a very curious beast. We are forced
to pass it strings for its filter criteria and hence must be aware of its string
handling behaviour. The criteria string consists of an operator (=, >, <, >=
etc.) followed by a value.
If no operator is specified, the "=" operator is assumed. The key issue is that
when using the "=" operator, AutoFilter performs a textual match, while using
any other operator results in a match by value. This gives us problems when
trying to locate exact matches for dates and numbers.
If we use "=", Excel matches on the text that is displayed in the cell, i.e. the
formatted number. As the text displayed in a cell will change with different
regional settings and Windows language version, it is impossible for us to
create a criteria string that will locate an exact match in all locales.
There is a workaround for this problem. When using any of the other filter
criteria, Excel plays by the rules and interprets the criteria string according
to US formats. Hence, a search criterion of ">=02/01/2001" will find all dates
on or after 1st Feb, 2001, in all locales.
We can use this to match an exact date by using two AutoFilter criteria. The
following code will give an exact match on 1st Feb, 2001 and will work in any
locale: