PDA

View Full Version : VBA Lag/Delay Issue on Import Command Button



timdonahu1
01-11-2019, 09:43 AM
Hi, one of the macro command buttons seems to be taking longer than it use to. Not sure if the macro is corrupted or if it could be better written.


Sub Import_BBH()
'






Application.EnableCancelKey = xlDisabled




Dim currentname As String
Dim sourcename As String
Dim PLF_B As String
Dim TDPVAL As String


Application.ScreenUpdating = False
Application.DisplayAlerts = False




PLF_B = Worksheets("Macro").Range("A3") & Range("B3").Value
TDPVAL = Worksheets("Macro").Range("A4") & Range("B4").Value

currentname = ActiveWorkbook.Name


'Import PLF B


Workbooks.Open Filename:=PLF_B
sourcename = ActiveWorkbook.Name
Range("A1").Select
Cells.Select
Selection.Copy
Workbooks(currentname).Activate
Sheets("PLF B").Select
Range("A1").Select
ActiveSheet.Paste
Workbooks(sourcename).Activate
ActiveWorkbook.Close Savechanges:=False

'Import TDPVAL


Workbooks.Open Filename:=TDPVAL
sourcename = ActiveWorkbook.Name
Range("A1").Select
Cells.Select
Selection.Copy
Workbooks(currentname).Activate
Sheets("TDPVAL").Select
Range("A1").Select
ActiveSheet.Paste
Workbooks(sourcename).Activate
ActiveWorkbook.Close Savechanges:=False

Sheets("Macro").Select
Range("A1").Select
End Sub


Sub Import_Prelim_Basket()


'Imports Prechecked Basket






Application.EnableCancelKey = xlDisabled




Dim currentname As String
Dim sourcename As String
Dim PLF_B As String


Application.ScreenUpdating = False
Application.DisplayAlerts = False




Prechecked_Basket = Worksheets("Macro").Range("A5") & Range("B5").Value



currentname = ActiveWorkbook.Name


'Import PLF B


Workbooks.Open Filename:=Prechecked_Basket
sourcename = ActiveWorkbook.Name
Range("A1").Select
Cells.Select
Selection.Copy
Workbooks(currentname).Activate
Sheets("Final Basket").Select
Range("A1").Select
ActiveSheet.Paste
Workbooks(sourcename).Activate
ActiveWorkbook.Close Savechanges:=False



Sheets("Macro").Select
Range("A1").Select
End Sub

Please let me know if you have any suggestions on how to make this faster. Thank you!!

Rob342
01-11-2019, 12:38 PM
There a lot of .select which will slow code down, filenames are not the same !
Are you trying to import data from 3 files and are these closed when trying to open

If you can give us a step by step on what you are trying to achieve then it would make it simpler to cure

Paul_Hossler
01-12-2019, 08:17 AM
1. I added CODE tags to post #1 -- you can use the [#] icon to insert them next time and paste your macro between

2, It would seem that this selects all the cells on the worksheet and then copies them all -- probably lots of blanks



Cells.Select
Selection.Copy


Without seeing what the data actually looks like, it's hard to offer alternatives

Also, as Rob342 said, you normally don't need to .Select an object to act on it