Improving the performance of FOR loop

后端 未结 3 805
时光取名叫无心
时光取名叫无心 2020-12-04 00:49

I am comparing sheets in a workbook. The workbook has two sheets named PRE and POST with the same 19 columns in each. The number of rows varies every day but are same for th

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-04 01:12

    Perhaps you can go with 2 adjustments, although their performance impact will be only very small:

    ' prepare references to worksheets
    Dim WorksheetPRE As Worksheet
    Dim WorksheetPOST As Worksheet
    Set WorksheetPRE = ActiveWorkbook.Worksheets("PRE")
    Set WorksheetPOST = ActiveWorkbook.Worksheets("POST")
    

    and then, in your code, replace ActiveWorkbook.Worksheets("PRE") for WorksheetPRE etc.

    I think no other significant optimizations are possible when you stay in Excel. Remember, Microsoft Excel is primarily a spreadsheet calculator, not a data-table processing tool.

    If I really needed to speed-up the comparisons, then I would go with one of these approaches:

    • link Excel worksheet to Microsoft Access as table and perform the comparison in Access (easiest)

    • as the above, but instead of linking the table, import it

    • as the above two, but use Microsoft SQL Server (Express version is free)

提交回复
热议问题