Consulting

Results 1 to 3 of 3

Thread: VBA Lag/Delay Issue on Import Command Button

  1. #1

    Exclamation VBA Lag/Delay Issue on Import Command Button

    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!!
    Last edited by Paul_Hossler; 01-12-2019 at 08:12 AM. Reason: Added CODE Tags

  2. #2
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location
    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

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    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
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •