I built an add-in that matches descriptions to a word list library in a different document.
My loop does the same thing over and over, but one loop takes just over a second to complete where 10 takes around 3 seconds per iteration, with 20 it goes to an average of 4 seconds, but 200 takes hours to complete.
A snippet of the code:
For Each rRow In CoAsh.Range(matchRange.Address).Rows
pctDone = i / rowCount
With frmProgress
.LabelCaption.Caption = "Processing account " & i & " of " & rowCount
.LabelProgress.Width = pctDone * (.FrameProgress.Width)
.LabelPercent = Round(pctDone * 100, 0) & "%"
End With
DoEvents
accArray = sh.Range("A2:A" & lRow).Value
For b = LBound(accArray) To UBound(accArray)
accString = accArray(b, 1)
sh.Cells(b + 1, 3).Value = levenshtein(CoAsh.Cells(rRow.Row, AccCol), accString, True)
Next b
sh.Select
sh.AutoFilter.Sort.SortFields.Clear
sh.AutoFilter.Sort.SortFields.Add Key:=Range("C1:C" & lRow), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortTextAsNumbers
With sh.AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
sh.Range("B2:B6").Copy
sh.Range("I2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
sh.Range("$I$2:$I$6").RemoveDuplicates Columns:=1, Header:=xlNo
sh.Range("I2:I6").Copy
CoAsh.Select
CoAsh.Cells(rRow.Row, 8).Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
i = i + 1
Next rRow