Optimize code to minimize runtime of the macro

后端 未结 2 1797
孤街浪徒
孤街浪徒 2021-01-26 03:10

I have been writing some macros to perform some astrological calculations (calculating sign, lunar mansion, D9 & D60). The raw data is in the following format:

2条回答
  •  被撕碎了的回忆
    2021-01-26 03:52

    Here are some tips that will make a huge difference to your code execution time:

    1. Use Option Explicit and declare your variables as the most appropriate date type - only use Variant when you need to.
    2. Store your data a numbers (not strings) and use cell format to display as you want
    3. Don't loop over (large) ranges. Copy the range data to a variant array, and loop the array. Copy the result back to the sheet at the end. There is lots of examples of this on SO and elsewhere.

    To display a number as Deg Minutes Seconds use number format [h]°mm'ss\" This leverages the time format, so you need to create the number value as Deg/24 + Min/1440 + Sec/86400 Eg 293°44'23" has the value 12.2391550925926

提交回复
热议问题