- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
10#
發表於 2012-12-30 08:16
| 只看該作者
回復 9# yanto913 - Option Explicit
- Sub 查詢功能()
- Dim Ex_Name As String, Ex_公司
- 'Name 是VBA的關鍵字請避免使用
- '關閉顯示
- Application.ScreenUpdating = False
- With Sheets("查詢")
- Ex_Name = .Range("F1") '姓名
- Ex_公司 = .Range("B1") '公司
- ' .UsedRange.Offset(2).Clear '清除舊有的查詢
- End With
- With Sheets("聯絡人")
- G = .[B65536].End(xlUp).Row
- For I = 2 To G
- '萬用字元收尋
- ' If .Cells(I, 2) Like "*" & Ex_Name & "*" Then '只查姓名
- If .Cells(I, 1) Like "*" & Ex_公司 & "*" And .Cells(I, 2) Like "*" & Ex_Name & "*" Then '查 姓名及公司
- 'If .Cells(I, 1) Like "*" & Ex_公司 & "*" Or .Cells(I, 2) Like "*" & Ex_Name & "*" Then '可查姓名 Or 公司
- .Range(.Cells(I, 1), .Cells(I, 10)).Copy
- c = Sheets("查詢").[a65536].End(xlUp).Row
- Sheets("查詢").Cells(c + 1, 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- End If
- Next I
- End With
- Application.ScreenUpdating = True '開啟顯示
- End Sub
複製代碼 |
|