need help because vba code is running slow

roykana

Active Member
Joined
Mar 8, 2018
Messages
311
Office Version
  1. 2010
Platform
  1. Windows
Dear all Master,
vba code runs slow for 100000 row records even though I'm using vba code with dictionaries and arrays. Please solve.
and also why the code run time result is different and I attached a screenshot of the time result.


thanks
roykana

VBA Code:
Sub Demo03()
Dim Rng As Range, Ds As Range, n As Long, Dic As Object, Source As Variant
Dim startTime As Double
Dim endTime As Double
Dim t
t = Timer
endTime = Timer
'Dim startTime As Double
'Dim endTime As Double
Application.ScreenUpdating = False
With Sheets("data")
    Source = .Range("h1").CurrentRegion.Resize(, 2)
End With
Set Dic = CreateObject("scripting.dictionary")
Dic.CompareMode = vbTextCompare
For n = 2 To UBound(Source, 1)
    Dic(Source(n, 1)) = n
Next
With Sheets("data")
    Set Rng = .Range(.Range("c2"), .Range("c" & Rows.Count).End(xlUp))
    For Each Ds In Rng
        If Dic.Exists(Ds.Value) Then
            Ds.Offset(, 1) = Source(Dic(Ds.Value), 1)
'            Ds.Offset(, 3) = source(Dic(Ds.Value), 3)
        End If
    Next Ds
End With


Application.ScreenUpdating = True

Debug.Print "Demo-03????:" & amp; amp; endTime - startTime
Debug.Print "It's done in: " & Timer - t & " seconds"
End Sub
 

Attachments

  • result time.JPG
    result time.JPG
    21.3 KB · Views: 21

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
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