Refining code

roi santos

Board Regular
Joined
Oct 3, 2008
Messages
57
Hi

I have created a code for importing data from an excel sheet to the active workbook. The macro works fine but just take a bit too long, as I'm intending to copy several columns I think that this will become a problem. I wonder if you can give some advice on how to accelarate the macro; given its complexity it should not be taking so long.

Any thoughts?

Many thanks

Sub doCopies2()
Dim DestWB As Workbook: Set DestWB = ActiveWorkbook
Dim DestWS As Worksheet: Set DestWS = ActiveSheet
Dim DestCLL As Range: Set DestCLL = ActiveCell
Dim UserChoice
UserChoice = Application.GetOpenFilename(FileFilter:="Text Files (*.xls),*.xls")


If TypeName(UserChoice) = "Boolean" Then Exit Sub
Application.ScreenUpdating = False
Dim SrcWB As Workbook
Set SrcWB = Application.Workbooks.Open(UserChoice)
SrcWB.Worksheets(1).Range(Range("C50"), Range("C50").End(xlDown)).Copy

DestWS.Activate
DestCLL.Offset(1, 0).Activate
ActiveSheet.Paste

Application.DisplayAlerts = False
SrcWB.Close savechanges:=False
Application.DisplayAlerts = True
Application.ScreenUpdating = True

End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
If I understand the code correctly, it appears like the delay is coming from the file that Excel is opening and not from the process of copying. There really isn't a way that I know of to speed this up and the performance is going to depend on the size of the Excel file you are opening. (i.e. a bigger file size = slower macro performance)
 
Upvote 0

Forum statistics

Threads
1,215,409
Messages
6,124,733
Members
449,185
Latest member
hopkinsr

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