作者Tobeyla (oPTTo阿宝)
看板Office
标题[问题] Excel筛选横向多条件资料(vba)
时间Fri Dec 30 16:00:40 2016
软体: Excel
版本: 2003
板友好~
我有一份依日期横向排列的文件
我想要用巨集搜寻指定输入的日期区间
EX:
input: 12/8~12/15
output: 12/8~12/15所有栏位的资料,其他日期隐藏
如果筛选单一个日期的之前有参考板友提供的方式:
Sub 搜寻日期()
Dim i
As Integer
For i = 8
To 122
If Cells(15, i) <> Cells(15, 2)
Then //在B15储存格输入日期
Cells(15, i).EntireColumn.Hidden =
True
End If
Next i
End Sub
但是多日期的只有很笨的试着先output整个区间的日期
然後想要用or的逻辑来做筛选
Sub 搜寻日期区间()
Dim diff
As Integer
Dim Date_Column
As Integer
Dim Var
As Integer
Dim i
As Integer
diff = Cells(14, 2) - Cells(14, 1)
Var = 0
For Date_Column = 42
To 42 + diff
Cells(Date_Column, 1) = Cells(14, 1) + Var
Var = Var + 1
Next Date_Column
For i = 8
To 122
If Cells(15, i).Value <> Range("A42:A51").Value Then
Cells(15, i).EntireColumn.Hidden =
True
End If
Next i
End Sub
但会在上色这行出现异常,想请问要怎麽改才能正常执行呢?
或者是有没有更聪明的方式可以筛选多范围资料呢?
感谢了~
--
╔════╗ ╔══╗ ╔═══╗ ╔════╗ ╔╗ ╔╗
║████║ ╔◢██◣╗ ║███◣╗ ║████║ ║◣╚╝◢║
╚╗ █ ╔╝ ║█╔╗█║ ║█▄▄◤╝ ║█▄▄▄╝ ╚◥◣◢◤╝
║ █ ║ ║█╚╝█║ ║███◣╗ ║█ ══╗ ╚╗█╔╝
║ █ ║ ╚◥██◤╝ ║█▄▄◤╝ ║████║ ║█║
╚══╝ ╚══╝ ╚═══╝ ╚════╝ ╚═╝ fooldoglulu
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 122.146.70.152
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Office/M.1483084843.A.48C.html
※ 编辑: Tobeyla (122.146.70.152), 12/30/2016 16:01:53
2F:→ soyoso: 或是以worksheetfunction.countif当为0时 12/30 16:40
3F:→ soyoso: iserror配合application.match为真时 12/30 16:42
4F:→ Tobeyla: 感谢~ 之前没碰过VBA的语法感觉有点复杂~ 我再依你的方式 12/31 02:05
5F:→ Tobeyla: 研究看看~ <(_ _)> 12/31 02:05