Dim your variable at the top of the macro as the correct variable type, proper basic programming:

Option Explicit

Private Sub CommandButton1_Click()
Dim y As Long
'etc....