在Excel中使用宏过滤数据 [英] Filtering Data using a macro in Excel

查看:328
本文介绍了在Excel中使用宏过滤数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一行代码使用excel中的宏来过滤掉数据。我想让它在一列过滤出两个不同的标准。请看下面的代码。从谷歌看,它应该工作,但它不是..

  Sub Unmet_Projects()

With Sheet1
.AutoFilterMode = False
.Range(A1:CA1)。AutoFilter
.Range(A1:CA1)。AutoFilter Field:= 3,Criteria1:=Filled ,运算符:= xlAnd,Criteria2:=Requested,VisibleDropDown:= False
End with

End Sub


解决方案

我相信应该是运算符:= xlOr 而不是$ code>运算符:= xlAnd ,因为列3(列 C )中的值只能已满足 请求



如果您希望在过滤器中包含更多值,我建议使用以下代码:

  .Range(A1:CA1)。AutoFilter字段:= 3,条件1:=数组(完成,请求,部分分配,未分配 ,etc ...),运算符:= xlFilterValues 


I have a line of code to filter out data using a macro in excel. I am wanting it to filter out two different criteria on one column. Please see the code below. From looking on google, it should work but it isnt..

Sub Unmet_Projects()

With Sheet1
    .AutoFilterMode = False
    .Range("A1:CA1").AutoFilter
    .Range("A1:CA1").AutoFilter Field:=3, Criteria1:="Fulfilled", Operator:=xlAnd, Criteria2:="Requested", VisibleDropDown:=False                    
End With

End Sub

解决方案

I believe it should be Operator:=xlOr and not Operator:=xlAnd since the values in column 3 (column C) can be only Fulfilled or Requested.

If you wish to include more values in the filter then I'd recommend the following instead:

.Range("A1:CA1").AutoFilter Field:=3, Criteria1:=Array("Fulfilled", "Requested", "Partially Assigned", "Not yet assigned", "Assigned", "etc..."), Operator:=xlFilterValues

这篇关于在Excel中使用宏过滤数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆