我有一些很好的帮助,让这个搜索工具在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