Possible with a faster code?

fredrerik84

Active Member
Joined
Feb 26, 2017
Messages
383
I have a big problem where im trying to look for similarities and I just built a working code however its way to slow :/ I thought maybe the Similarity function I call was the bottleneck but just writing a simple "1" to each of these cells also took quite awhile

Code:
Sub FindSimilarity()
Dim lr As Long, i As Long, j As Long
Dim vData As Variant
Dim str As String, str2 As String
Dim sheet As Worksheet
Set sheet = ActiveWorkbook.Sheets("Sheet1")
j = 2
lr = sheet.Cells(Rows.Count, "H").End(xlUp).Row
vData = sheet.Range("H2:H" & lr)




   For i = LBound(vData, 1) To UBound(vData, 1)
      m = 0
      str = vData(i, 1)
      If Not IsNull(str) Then
      
         For j = LBound(vData, 1) To UBound(vData, 1)
            str2 = vData(j, 1)
               If Not IsNull(str2) Then
                  Cells(i + 1, 13 + j).Value = Similarity(str, str2)
               End If
         Next j
      End If
   Next i
End Sub

Basically this code writes to about 1000 columns x 1000 rows .. Is there a better way to speed this code up ? was thinking to add all off this into another array ?
I don't need all off this data Just str , str2 and the highest value of each row..

This was a little crazy code as it takes over 5 min to complete on my system :)
 
Last edited:

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,224,823
Messages
6,181,185
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top