Home » excel » vba – Excel delete formula but keep values witha lot of rows

vba – Excel delete formula but keep values witha lot of rows

Posted by: admin May 14, 2020 Leave a comment

Questions:

I’m working with a macro excel. I’m trying to delete the formula but keep the values of the cells as it makes filtering/sorting so slow. I already tried the following:

Range("A2:E70000").Select
Selection.Copy 
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
    SkipBlanks :=False, Transpose:=False

and

Sheet1.Range("A2:E70000").Values = Sheet1.Range("A2:E70000").Values

but both of them take too long to finish(about 30mins. to complete). Are there any faster ways to do this? Thanks in advance.

How to&Answers:

Bracket your code with

Application.ScreenUpdating = False

and

Application.creenUpdting = True

and you should see performance improve dramatically.

Answer:

Visuals like selecting the cells are going to slow this down considerably. Also selecting to row 70,0000? If this is actually the case then fair enough, but if not then why?

Have edited your first code slightly. This will stop the screen updating until finished, won’t ‘select’ any cells (visually) and will find the last actual row that is in use instead of just blanket selecting a range in hope it gets everything.

Try:

Application.ScreenUpdating = False
with Sheet1.Range("A2:E" & Sheet1.Range("E" & .Rows.Count).End(xlUp).Row)
    .copy
    .PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
         SkipBlanks :=False, Transpose:=False
end with
Application.ScreenUpdating = True