Excel精英培训网

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

[已解决]资料筛选与筛选复制问题

[复制链接]
发表于 2017-7-31 12:48 | 显示全部楼层 |阅读模式
本帖最后由 lkk0063 于 2017-8-2 08:31 编辑

按下"AutoFilter"按钮,会自动跳出输入月份视窗,输入后会自动筛选 C 整个栏位与 BF 无空白栏位
1.想新增可输入一个筛选 D 整个栏位(输入16 旧筛选有 16 的资料)
2.将所有资料筛选后将复制到Output(如Output sheet)


最佳答案
2017-7-31 14:40
  1. Private Sub CommandButton1_Click()
  2. Dim n, n1
  3. n = InputBox("Pls  Input  Month")
  4. If n = "" Then Exit Sub
  5. If VBA.IsNumeric(n) <> True Then
  6.   MsgBox "Pls  Input  Value!!"
  7. Exit Sub
  8. End If
  9. If CInt(n) > 12 Or (n) < 1 Then
  10.   MsgBox "Pls  Check  Month!!"
  11. Exit Sub
  12. End If
  13. n1 = InputBox("Pls  Input  Day")
  14. With Sheets("Input")
  15. .Range("a2:bl" & [a65536].End(3).Row).AutoFilter Field:=3, Criteria1:=">=" & DateSerial(Year(Now), n, 1), Operator:=xlAnd, Criteria2:="<=" & DateSerial(Year(Now), n + 1, 0)
  16. .Range("d2").AutoFilter Field:=4, Criteria1:=n1
  17. .Range("BH2").AutoFilter Field:=60, Criteria1:="<>"
  18. End With
  19. End Sub
复制代码

TEST.zip

377.34 KB, 下载次数: 9

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2017-7-31 14:40 | 显示全部楼层    本楼为最佳答案   
  1. Private Sub CommandButton1_Click()
  2. Dim n, n1
  3. n = InputBox("Pls  Input  Month")
  4. If n = "" Then Exit Sub
  5. If VBA.IsNumeric(n) <> True Then
  6.   MsgBox "Pls  Input  Value!!"
  7. Exit Sub
  8. End If
  9. If CInt(n) > 12 Or (n) < 1 Then
  10.   MsgBox "Pls  Check  Month!!"
  11. Exit Sub
  12. End If
  13. n1 = InputBox("Pls  Input  Day")
  14. With Sheets("Input")
  15. .Range("a2:bl" & [a65536].End(3).Row).AutoFilter Field:=3, Criteria1:=">=" & DateSerial(Year(Now), n, 1), Operator:=xlAnd, Criteria2:="<=" & DateSerial(Year(Now), n + 1, 0)
  16. .Range("d2").AutoFilter Field:=4, Criteria1:=n1
  17. .Range("BH2").AutoFilter Field:=60, Criteria1:="<>"
  18. End With
  19. End Sub
复制代码
回复

使用道具 举报

 楼主| 发表于 2017-7-31 15:26 | 显示全部楼层
本帖最后由 lkk0063 于 2017-7-31 15:27 编辑
  1. Private Sub CommandButton1_Click()
  2. Dim n, n1
  3. n = InputBox("Pls  Input  Month")
  4. If n = "" Then Exit Sub
  5. If VBA.IsNumeric(n) <> True Then
  6.   MsgBox "Pls  Input  Value!!"
  7. Exit Sub
  8. End If
  9. If CInt(n) > 12 Or (n) < 1 Then
  10.   MsgBox "Pls  Check  Month!!"
  11. Exit Sub
  12. End If
  13. n1 = InputBox("Pls  Input  Day")
  14. With Sheets("Input")
  15. .Range("a2:bl" & [a65536].End(3).Row).AutoFilter Field:=3, Criteria1:=">=" & DateSerial(Year(Now), n, 1), Operator:=xlAnd, Criteria2:="<=" & DateSerial(Year(Now), n + 1, 0)
  16. .Range("d2").AutoFilter Field:=4, Criteria1:=n1
  17. .Range("BH2").AutoFilter Field:=60, Criteria1:="<>"

  18. Sheets(2).UsedRange.Clear
  19.     Sheets(1).UsedRange.SpecialCells(xlCellTypeVisible).Copy _
  20.         Destination:=Sheets(2).Range("A1")

复制代码
你好,
若想将资料sheet(1)复制sheet(2) A:D 栏位与 XX:YY栏位 红字部分如何修改?

Sheets(2).UsedRange.Clear
    Sheets(1).UsedRange.SpecialCells(xlCellTypeVisible).Copy _
        Destination:=Sheets(2).Range("A1")


回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-27 06:36 , Processed in 0.283055 second(s), 9 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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