.values=.values and macro speed

mbt2103

New Member
Joined
Aug 4, 2014
Messages
35
Hey all,

I have a question that should be simple, but I couldn't find any information on it in searches, and other people asking similar questions seemed to just generate confusion.

I'm putting together a rather large macro using Excel/VBA 2010, and I was having problems with "empty" cells not actually being empty. I found this nifty little gem (probably on this site):

Range("A:J").Select
With Selection
.Value = .Value
End With

4 lines, fixed all my problems.

However, after implementing it, and while testing further additions to the macro, I discovered that every time it ran, it ran a little slower. One iteration took 15 minutes, when it usually takes <10 seconds. Specifically, making borders becomes very slow. This doesn't end until I reset my computer entirely.

My first thought was to clear the cache. When I searched for methods, most responses were confused "what cache?" and "there's nothing to clear" responses. So now I'm lost.

It seems the values for the entire sheet are being stored somewhere, taking up computing power, and slowing down everything else, and they're not being deleted unless the computer is reset. I'm going to call this chunk of values a "cache".

How do I clear this "cache"?

Thanks for the help! (and, if you're like me, have fun with the mystery!)
 

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
Just a guess, but assuming you are not using anywhere near all the cells in columns A:J, try this:

With Intersect(Columns("A:J"),Activesheet.UsedRange)
.Value = .Value
End With
 
Upvote 0
Or:

Code:
[COLOR=#333333]With Activesheet.UsedRange.Resize(,10)[/COLOR]
[COLOR=#333333].Value = .Value[/COLOR]
[COLOR=#333333]End With[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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