[問題] Excel篩選橫向多條件資料(vba)

看板Office作者 (oPTTo阿寶)時間9年前 (2016/12/30 16:00), 9年前編輯推噓0(005)
留言5則, 2人參與, 最新討論串1/1
軟體: 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
或是以worksheetfunction.countif當為0時
12/30 16:40, 2F

12/30 16:42, , 3F
iserror配合application.match為真時
12/30 16:42, 3F

12/31 02:05, , 4F
感謝~ 之前沒碰過VBA的語法感覺有點複雜~ 我再依你的方式
12/31 02:05, 4F

12/31 02:05, , 5F
研究看看~ <(_ _)>
12/31 02:05, 5F
文章代碼(AID): #1OPXGhIC (Office)
文章代碼(AID): #1OPXGhIC (Office)