You are declaring x twice. Do not declare it in the userform - that makes 2x's and the userform is only operating on its own x. If you take the Publicx As Integer out of the userform it will work.