看板 Office 關於我們 聯絡資訊
軟體: 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
soyoso: https://i.imgur.com/Q8KnqfQ 類似這樣 12/30 16:35
soyoso: 或是以worksheetfunction.countif當為0時 12/30 16:40
soyoso: iserror配合application.match為真時 12/30 16:42
Tobeyla: 感謝~ 之前沒碰過VBA的語法感覺有點複雜~ 我再依你的方式 12/31 02:05
Tobeyla: 研究看看~ <(_ _)> 12/31 02:05