我有一些很好的幫助,讓這個搜索工具在Excel中工作,但我想知道是否有提高速度的空間。我做了一些研究,以及我對VB的理解,因爲我認爲最好的方法是使用UBOUND(array)。 '爲每個'會更快?我想知道是否有辦法隔離當前工作表中的記錄,或者它是否已經在L/UBOUND中執行此操作?如果是這樣,有沒有辦法做'忽略特殊字符'類似於SQL?在添加屏幕更新和計算後,我可以在整個運行時間內減少約10秒。此外,我在這個新循環之前使用FormulaR1C1進行搜索,它會限制超快速搜索的列數。在excel中加速循環
Range("W2:W" & LastRow).FormulaR1C1 = _
"=IF(ISERR(SEARCH(R1C23,RC[-22]&RC[-21]&RC[-20]&RC[-19]&RC[-18]&RC[-17]&RC[-16]&RC[-15]&RC[-15]&RC[-14]&RC[-13]&RC[-12]&RC[-11]&RC[-10]&RC[-9]&RC[-8]&RC[-7]&RC[-6]&RC[-5]&RC[-4]&RC[-3]&RC[-2]&RC[-1])),0,1)"
If WorksheetFunction.CountIf(Columns(23), 1) = 0 Then
Columns(23).Delete
任何幫助或建議,非常感謝。
Sub FindFeature()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim shResults As Worksheet
Dim vaData As Variant
Dim i As Long, j As Long
Dim sSearchTerm As String
Dim sData As String
Dim rNext As Range
Dim v As Variant
Dim vaDataCopy As Variant
Dim uRange As Range
Dim findRange As Range
Dim nxtRange As Range
Dim ws As Range
'Put all the data into an array
vaData = ActiveSheet.UsedRange.Value
'Get the search term
sSearchTerm = Application.InputBox("What are you looking for?")
'Define and clear the results sheet
Set shResults = ActiveWorkbook.Worksheets("Results")
shResults.Range("A3").Resize(shResults.UsedRange.Rows.Count, 1).EntireRow.Delete
Set uRange = ActiveSheet.UsedRange
vaData = uRange.Value
vaDataCopy = vaData
For Each v In vaDataCopy
v = Anglicize(v)
Next
Application.WorksheetFunction.Transpose (vaDataCopy)
ActiveSheet.UsedRange.Value = vaDataCopy
'Loop through the data
Set ws = Cells.Find(What:=uRange, After:="ActiveCell", LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not ws Is Nothing Then
Set findRange = ws
Do
Set nxtRange = Cells.FindNext(After:=ws)
Set findRange = nxtRange
Loop Until ws.Address = findRange.Address
ActiveSheet.UsedRange.Value = vaData
'Write the row to the next available row on Results
Set rNext = shResults.Cells(shResults.Rows.Count, 1).End(xlUp).Offset(1, 0)
rNext.Resize(1, uRange(vaData, 2)).Value = Application.Index(vaData, i, 0)
'Stop looking in that row after one match
End If
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Specialcells可以通過讓您通過較少的細胞搜索添加一些改進http://msdn.microsoft.com/en-us/library/office/ff196157(v=office.14).aspx – Jesse
是否使用'Anglicize'版本與此問題原始版本中的版本相同 - http://stackoverflow.com/revisions/17427039/1如果是這樣,那就非常不合適sary'Sheets(「Results」)。Activate' line in there which might have a effect on performance – barrowc
不幸的是,它是一個必須具備的功能。除非有更好的方法去做。也許一個msgbox然後轉移後? – cbrannin