It appears that a value that is used around the start of your program is null. Set variables equal to 0, "", or Nothing, instead of just defining them, especially at the start, to fix this problem. Or, move variables defined outside of the sub to the inside of the subs that they are used in.