codice:
 Private Sub Text1_KeyPress(KeyAscii As Integer)
    'Consente di digitare solo numeri nella casella di testo.
    If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 Then KeyAscii = 0
End Sub
Se vuoi la puoi trasformare in funzione