[問題] Excel篩選橫向多條件資料(vba)
軟體: 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://www.ptt.cc/bbs/Office/M.1483084843.A.48C.html
※ 編輯: Tobeyla (122.146.70.152), 12/30/2016 16:01:53
→
12/30 16:35, , 1F
12/30 16:35, 1F
→
12/30 16:40, , 2F
12/30 16:40, 2F
→
12/30 16:42, , 3F
12/30 16:42, 3F
→
12/31 02:05, , 4F
12/31 02:05, 4F
→
12/31 02:05, , 5F
12/31 02:05, 5F
Office 近期熱門文章
PTT數位生活區 即時熱門文章
-3
16