VBA 代码中命名单元格的使用会减慢宏的速度吗?

Does the usage of named cells in VBA code slow down the macro?

Does the usage of named cells in VBA code slow down the macro?

我假设如果您在 VBA 代码中使用一两个名为 cells/ranges 的代码,它不会对其执行时间产生太大影响。不过我很好奇namedcells/ranges的过度使用会不会拖慢宏

Impact of Named Ranges on SpreadSheet:

我找到了以下信息。

Named Ranges:
1. allows users to save time
2. enhances automated data analysis
But:
3. increases the size of files and significantly 
   slows down basic Excel functionality.

参考:https://medium.com/@rzacharia/excel-named-ranges-the-good-and-the-really-ugly-894e04fb16e5

Impact of Named Ranges on VBA Execution:

这取决于你如何使用它。 例如,如果您创建了大量命名范围并且在循环中调用它们,那么它会降低性能。因为每次excel都会需要解析名字

如果您使用的是范围 ("A1:A30") 而不是命名范围,那么与命名范围相比,Excel 不需要执行任何额外的操作。

为了测试这一点,我创建了一个命名范围 (A1:A30) 并以不同的计数在循环中调用它,这就是我发现的(提到的时间以秒为单位)。

NamedRange  Range   Loop Count
1.64         1.57   100000
3.3          3.17   200000
8.38         7.9    500000

结论:

1. If you are using Named Range with limited number and not using in loop with larger count then it may not create any issue.
2. It may slow down the performance 
   2.1 if you are using Named Range in loop with large count.
   2.2 if you are using large number of Named Ranges.

希望对您有所帮助。