Excel VBA-AdvancedFilter [英] Excel VBA - AdvancedFilter
问题描述
我正在尝试在VBA中动态过滤范围,而我正在使用的VBA无法正常工作,但我看不到逻辑上的原因.为说明起见,我在标题为"Full Stock Report
"的工作表中有一系列数据,其大小将发生变化,但在此示例中已对其进行了静态设置.保持在启动"Spitfire Aval Locations
"的工作表上的范围内,这也是动态的,但在此示例中我再次将其设置为静态.这对我来说听起来很简单,但是下面的代码行应用了一个过滤器,但是没有任何结果(我检查了一下,知道该过滤器中应该显示很多内容).
I am trying to filter a range dynamically in VBA and the VBA I am using is not working but I cannot see a logical reason as to why. To explain, I have a range of data in a sheet entitled "Full Stock Report
" the size of which will change but I've set it statically in this example... And I'm trying to filter it by a list of criteria held in a range on a sheet initiated "Spitfire Aval Locations
", again this is also dynamic but I've set as static again in this example. This sounds simple to me but the below line of code applies a filter but with no results (I have checked I know there are lots that should appear from this filter).
我的第二个问题是相关的,此VBA语句如何指示要过滤范围中的哪一列? (我担心这可能是我的问题....)
My second question is related, how does this VBA statement dictate which column in the range is being filtered ? (I fear this may be my issue ....)
Sheets("Full Stock Report").Range("A1:F20623").AdvancedFilter Action:=xlFilterInPlace,
CriteriaRange:=Sheets("Spitfire Aval Locations").range("A2:A228"), Unique:=False
推荐答案
要过滤的列是您调用.AdvancedFilter的第一个.Range.您发布的代码对A到F列进行了过滤.如果您只想根据A列中的值进行过滤,则看起来会更像这样:
The column to filter on is the first .Range that you call .AdvancedFilter on. The code you posted filters columns A through F. If you wanted to only filter based on values in column A, it would look more like this:
Sheets("Full Stock Report").Range("A1:A20623").AdvancedFilter _
Action:=xlFilterInPlace, _
CriteriaRange:=Sheets("Spitfire Aval Locations").Range("A2:A228"), _
Unique:=False
这篇关于Excel VBA-AdvancedFilter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!