I believe that you need to also dim y and z as welltry replacingDim x as integerwithDim x as integer, y as integer, z as integer