vba - Speed up Excel Macro as Opening -


so whole scope of excel file is copy , paste other 27 external files current excel file 1 one. show mean, following code examples , stimulated capture picture.enter image description here

macros(line # including space line):

1. importing sub

in file, have 27 subs this. it's longer example. real macro has 179 lines total. in example, has 51 lines.

the thing changed row numbers word row in vba code in line 6.

    sub import_nj()      dim row integer, pathfileopen string, namefileopen string,      typefileopen string, fullfilename string, tabcopy string, modelfilename string      let row = worksheets("control_table").cells("2", "d").value     let pathfileopen = worksheets("control_table").cells(row, "a").text     let namefileopen = worksheets("control_table").cells(row, "b").text     let typefileopen = worksheets("control_table").cells(row, "c").text     let fullfilename = pathfileopen & "\" & namefileopen & typefileopen     let tabcopy = worksheets("control_table").cells(row, "j").text     let modelfilename = worksheets("control_table").cells("10", "b").text          application.asktoupdatelinks = false         application.displayalerts = false         application.calculation = xlcalculationmanual         workbooks.open filename:=fullfilename, updatelinks:=0      'copy income statement         workbooks(namefileopen).worksheets("total_reports").cells("9", "c").resize(5, 120).copy         'revenues         workbooks(modelfilename).worksheets(tabcopy).cells("4", "aw").resize(5, 120).pastespecial xlpastevalues         workbooks(namefileopen).worksheets("total_reports").cells("18", "c").resize(4, 120).copy        'prod costs         workbooks(modelfilename).worksheets(tabcopy).cells("11", "aw").resize(4, 120).pastespecial xlpastevalues         workbooks(namefileopen).worksheets("total_reports").cells("25", "c").resize(26, 120).copy       'employee related thru maintenance         workbooks(modelfilename).worksheets(tabcopy).cells("17", "aw").resize(26, 120).pastespecial xlpastevalues         workbooks(namefileopen).worksheets("total_reports").cells("53", "c").resize(3, 120).copy       'd&a         workbooks(modelfilename).worksheets(tabcopy).cells("46", "aw").resize(3, 120).pastespecial xlpastevalues            application.cutcopymode = false         workbooks(namefileopen).close         application.displayalerts = true      end sub 
  1. batch import sub

although shows 7 callings, have 27 calling in file

    sub batch_import()     application          call import_nj            call import_md          call import_pa            call import_okc          call import_ca             call import_hi          call import_in          end          application.calculation = xlcalculationautomatic         activeworkbook.save         application.displayalerts = true          msgbox _         ("batch loading completed.")      end sub 

what tried:

  1. turn off automatic calculation in each sub, see in first example macro. , others application many could.

  2. i didn't shut down screen updating since manager wants see it.

  3. i activate automatic calculating @ end of patch sub.

i guess reseason slowing down whole process have more 27 subs in module.also, there bunch of formulas filled in worksheets.

are there ways speed macro regarding opening file , running it? let me know if need elabrate more on question. in advance , read through question. : )

you pasting values; transfer values directly instead , remove clipboard consideration. either source or target referenced within ... end with.

this,

    workbooks(namefileopen).worksheets("total_reports").cells("9", "c").resize(5, 120).copy         'revenues     workbooks(modelfilename).worksheets(tabcopy).cells("4", "aw").resize(5, 120).pastespecial xlpastevalues     workbooks(namefileopen).worksheets("total_reports").cells("18", "c").resize(4, 120).copy        'prod costs     workbooks(modelfilename).worksheets(tabcopy).cells("11", "aw").resize(4, 120).pastespecial xlpastevalues     workbooks(namefileopen).worksheets("total_reports").cells("25", "c").resize(26, 120).copy       'employee related thru maintenance     workbooks(modelfilename).worksheets(tabcopy).cells("17", "aw").resize(26, 120).pastespecial xlpastevalues     workbooks(namefileopen).worksheets("total_reports").cells("53", "c").resize(3, 120).copy       'd&a     workbooks(modelfilename).worksheets(tabcopy).cells("46", "aw").resize(3, 120).pastespecial xlpastevalues 

becomes,

with workbooks(namefileopen).worksheets("total_reports")     workbooks(modelfilename).worksheets(tabcopy).cells("4", "aw").resize(5, 120) = _         .cells("9", "c").resize(5, 120).value2         'revenues     workbooks(modelfilename).worksheets(tabcopy).cells("11", "aw").resize(4, 120) = _         .cells("18", "c").resize(4, 120).value2        'prod costs     workbooks(modelfilename).worksheets(tabcopy).cells("17", "aw").resize(26, 120) = _         .cells("25", "c").resize(26, 120).value2       'employee related thru maintenance     workbooks(modelfilename).worksheets(tabcopy).cells("46", "aw") = _         .cells("53", "c").resize(3, 120).value2        'd&a end 

as mentioned in comments, if external files @ or on 1mb filesize area, save them .xlsb (excel binary) reduce load time.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -