返回列表 上一主題 發帖

[發問] 多筆EXCEL搜尋的用法-延伸問題

Set Rng = Sh.Range("D:D").Find(TheSh.TextBox1)
改成D欄模糊搜尋
學海無涯_不恥下問

TOP

本帖最後由 Hsieh 於 2011-6-9 08:51 編輯

回復 5# mark15jill
  1. Sub ex()
  2. Dim Ar()
  3. Application.ScreenUpdating = False
  4. With Sheet1
  5. nd = IIf(.OptionButton1 = True, 2, IIf(.OptionButton2 = True, 5, 0))
  6. mystr = "*" & .TextBox1 & "*"
  7. If nd = 0 Then MsgBox "請選擇查詢項目": Exit Sub
  8. fs = Dir(ThisWorkbook.Path & "\*年度.xls")
  9. Do Until fs = ""
  10.    With Workbooks.Open(ThisWorkbook.Path & "\" & fs)
  11.      For Each Sh In .Sheets
  12.      With Sh
  13.      If Application.CountA(.Columns(nd)) = 0 Then GoTo 10
  14.         For Each a In .Columns(nd).SpecialCells(xlCellTypeConstants)
  15.         If a Like mystr Then
  16.            ReDim Preserve Ar(s)
  17.            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)
  18.            s = s + 1
  19.         End If
  20.         Next
  21. 10
  22.      End With
  23.      Next
  24.     .Close 0
  25.    End With
  26.    fs = Dir
  27. Loop
  28. If s > 0 Then
  29. .[A3:G65536] = ""
  30. .[A3].Resize(s, 7) = Application.Transpose(Application.Transpose(Ar))
  31. Else
  32. MsgBox "查無資料"
  33. End If
  34. End With
  35. Application.ScreenUpdating = True
  36. End Sub
複製代碼
學海無涯_不恥下問

TOP

        靜思自在 : 人的心地是一畦田,土地沒有播下好種子,也長不出好的果實。 -
返回列表 上一主題