Excel之VBA中find方法運用
(2016-03-24 11:27:53)
标签:
excelvbafind快快速 |
分类: Excel |
在Excel中,如果不使用Vlookup之類的函數,使用find方法較使用循環遍歷匹配的方法而言,速度快約10位。
Sheets(2).Cells(1, "M").Value = Time
Application.ScreenUpdating = False '關閉屏幕刷新,減少資料開銷
i = 2
Do While Sheets(2).Cells(i, "A").Value <> ""
Get_Name = Sheets(2).Cells(i, "A").Value
'假定表2中通過A例之姓名尋找相表1中B例值(使用Vlookup即可)
Set Is_ExistFlag= Sheets(1).Range("C:C").Find(Get_Name)
If Not Is_ExistFlag Is Nothing Then ‘此語句非常重要,如果無匹配結果就會崩錯,導致中斷
Sheets(1).Select
Target_Result = Sheets(1).Range("C:C").Find(Get_Name).Select
'是否找到
If Target_Result = True Then
Get_Current_Row = ActiveCell.Row
Sheets(2).Cells(i, "B").Value = Sheets(1).Cells(Get_Current_Row,
"B").Value '取值
End If
End If
i = i + 1
Loop
Application.ScreenUpdating = True '恢復屏幕刷新
Sheets(2).Cells(2, "M").Value = Time
Sheets(2).Select