Regarding "Subscript out of range" Arrays are normally base 0, so a 4 item array has items 0, 1, 2 & 3. It is common for increments etc. to finish one number higher so you may need to use "From 0 to J -1" . Arrays can be made to start at 1 by using Option Base 1 at the head of your code, in which case From 1 to J may be correct.