Hi,
You need some defensive programming. Try code like the following:
Comments:
a. The use of 'Integer' is archaic (but not wrong) and should probably be replaced by 'long' which stands for 'long integer'. The internal representation in Excel is of type 'long' anyway.
b. To prevent typos from ruining days and weeks of work 'Option Explicit' is NEEDED at the top of each code module. This prevents errors caused by missspellings and FORCES every variable to be DECLARED (e.g. Dim i as Integer). https://www.excel-easy.com/vba/examp...-explicit.html
Lewis
Bookmarks