How do I transfer large ranges into memory first, then do the comparison vs memory instead of by a cell range?

Tardisgx

Board Regular
Joined
May 10, 2018
Messages
81
The below macro clears cells that do not match with the D column range. The issue is my required ranges are too large for the macro to run on my computer.

Sub REMOVEPIDS()Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False


Dim Rng As Range, Dn As Range
Set Rng = Range("D2:D35525") 'Range to match against


With CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare

For Each Dn In Rng: .Item(Dn.Value) = Empty: Next

Set Rng = Range("F2:DVF62601") ' Range to clear

For Each Dn In Rng
If Not .exists(Dn.Value) Then Dn.ClearContents
Next Dn

End With
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.EnableEvents = True
End Sub
 
Last edited:
Why are you looping through all the cells in F2:DVF6260?

Couldn't you loop through the values/items in the dictionary and do a find/replace on that range?
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Cool thanks for your input; note to self don't mess with format when its working already; I also appreciate your attempts at my problem.

I had to stop your macro running when I got home today (the one i left overnight) over 12 hours although it did say I interrupted it;the macro seemed to have reached halfway down column D :/

My original macro with select special constants as the defined range completes the clearing process in eerily exactly 10 minutes; will be my go to selector for massive ranges.

Do I need to mark this thread solved somehow?
 
Upvote 0
Glad you got it sorted & thanks for the feedback.

No need to mark the thread as solved.
 
Upvote 0

Forum statistics

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