Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 3301|回复: 5

满足条件再进行筛选

[复制链接]
发表于 2021-4-18 13:46 | 显示全部楼层 |阅读模式
附件表格,先在数据1列筛选n1,筛选后,然后在数据3这列看有没有n2(隐藏单元格有n2不算),如果有在数据3列筛选n2,如果没有就不进行第二次筛选。
Sub 宏2()
Dim n1 As Integer
  Dim n2 As Integer
Columns("B:E").Select
    Selection.AutoFilter
     n1 = Application.InputBox("n1=", , , , , , , 1)
      n2 = Application.InputBox("n2=", , , , , , , 1)
    ActiveSheet.Range("$B$1:$E$6868").AutoFilter Field:=1, Criteria1:=n1
   if ........ then ActiveSheet.Range("$B$1:$E$6868").AutoFilter Field:=1, Criteria1:=n2
  end if
End Sub

多条件筛选.rar

16.13 KB, 下载次数: 2

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2021-4-18 15:22 | 显示全部楼层
Sub demo()

   With Range("$B$1:$F$6868")
      .AutoFilter Field:=5, Criteria1:=""
      n1 = Application.InputBox("n1=", Type:=1)
      .AutoFilter Field:=1, Criteria1:=n1
      n2 = Application.InputBox("n2=", Type:=1)
      For i = 1 To [a1].End(xlDown).Row
         If Rows(i).Hidden Then
            Cells(i, "f").Value = " "
         Else
            Cells(i, "f").Value = ""
            If Cells(i, "d").Value = n2 Then exists2 = 1
         End If
      Next
      If exists2 Then .AutoFilter Field:=3, Criteria1:=n2
   End With

End Sub


祝順心,南無阿彌陀佛!




多条件筛选.rar

18.91 KB, 下载次数: 2

回复

使用道具 举报

 楼主| 发表于 2021-4-18 15:50 | 显示全部楼层
感谢版主,有没有不用循环的方法呢,实际的表格数据几千行。能不能用find函数结合可见单元格SpecialCells(xlCellTypeVisible)来判断,但是总是报错,烦劳版主
回复

使用道具 举报

 楼主| 发表于 2021-4-18 15:51 | 显示全部楼层
cutecpu 发表于 2021-4-18 15:22
Sub demo()

   With Range("$B$1:$F$6868")

感谢版主,有没有不用循环的方法呢,实际的表格数据几千行。能不能用find函数结合可见单元格SpecialCells(xlCellTypeVisible)来判断,但是总是报错,烦劳版主
回复

使用道具 举报

发表于 2021-4-18 16:02 | 显示全部楼层
youyichen 发表于 2021-4-18 15:51
感谢版主,有没有不用循环的方法呢,实际的表格数据几千行。能不能用find函数结合可见单元格SpecialCells ...

您好,循環最主要是 給新增的輔助列 F 填值( 全型空白代表該行為隱藏行)
然後再搭配 AutoFilter 過濾,要不然 AutoFilter 沒辦法過濾隱藏行!


回复

使用道具 举报

发表于 2021-4-19 14:47 | 显示全部楼层
youyichen 发表于 2021-4-18 15:51
感谢版主,有没有不用循环的方法呢,实际的表格数据几千行。能不能用find函数结合可见单元格SpecialCells ...

用ado给你做的,速度没问题


多条件筛选.rar

28.08 KB, 下载次数: 3

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-27 07:44 , Processed in 0.281920 second(s), 8 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表