Slow VBA code?

  • Thread starter Thread starter Gijs Breedveld
  • Start date Start date
G

Gijs Breedveld

I have code which clears a table which was generated the previous run. The
code is:

Range("b20000:o20000").Select
Selection.AutoFill Destination:=Range("b10:o20000"), Type:=xlFillDefault
Range("b10:o20000").Select

I just want to clear the contents and the formats of the previous table
before I build up the next table.

Is there code which can do this faster? It is very slow. Takes about 60
seconds.

Best regards, Gijs
 
try either of these:

Sub test()
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
With Range("b20000:o20000")
.Clear
End With
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
End Sub

Sub test2()
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
Range("b20000:o20000").AutoFill Destination:=Range("b10:o20000"), _
Type:=xlFillDefault
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
End Sub
 
You can get rid of the select

Range("b20000:o20000").AutoFill Destination:=Range("b10:o20000"),
Type:=xlFillDefault
Range("b10:o20000").Select

but I doubt that will make much difference. Also try turning screenupdating
off and setting calculation to manual, and reset after.


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
Bob,

Thanks .

Best regards,

Gijs

Bob Phillips said:
You can get rid of the select

Range("b20000:o20000").AutoFill Destination:=Range("b10:o20000"),
Type:=xlFillDefault
Range("b10:o20000").Select

but I doubt that will make much difference. Also try turning screenupdating
off and setting calculation to manual, and reset after.


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top