- 帖子
- 4901
- 主題
- 44
- 精華
- 24
- 積分
- 4916
- 點名
- 142
- 作業系統
- Windows 7
- 軟體版本
- Office 20xx
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台北
- 註冊時間
- 2010-4-30
- 最後登錄
- 2026-7-16
                
|
本帖最後由 Hsieh 於 2011-6-9 08:51 編輯
回復 5# mark15jill - Sub ex()
- Dim Ar()
- Application.ScreenUpdating = False
- With Sheet1
- nd = IIf(.OptionButton1 = True, 2, IIf(.OptionButton2 = True, 5, 0))
- mystr = "*" & .TextBox1 & "*"
- If nd = 0 Then MsgBox "請選擇查詢項目": Exit Sub
- fs = Dir(ThisWorkbook.Path & "\*年度.xls")
- Do Until fs = ""
- With Workbooks.Open(ThisWorkbook.Path & "\" & fs)
- For Each Sh In .Sheets
- With Sh
- If Application.CountA(.Columns(nd)) = 0 Then GoTo 10
- For Each a In .Columns(nd).SpecialCells(xlCellTypeConstants)
- If a Like mystr Then
- ReDim Preserve Ar(s)
- Ar(s) = Array(fs, .Name, s + 1, .Cells(a.Row, 2).Value, .Cells(a.Row, 4).Value, .Cells(a.Row, 1).Value, .Cells(a.Row, 5).Value)
- s = s + 1
- End If
- Next
- 10
- End With
- Next
- .Close 0
- End With
- fs = Dir
- Loop
- If s > 0 Then
- .[A3:G65536] = ""
- .[A3].Resize(s, 7) = Application.Transpose(Application.Transpose(Ar))
- Else
- MsgBox "查無資料"
- End If
- End With
- Application.ScreenUpdating = True
- End Sub
複製代碼 |
|