View Single Post
 
Old 03-24-2019, 08:35 AM
gmaxey gmaxey is offline Windows 10 Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  If Not fcnValidate(TextBox1, "Number") Then
    Cancel = True
  End If
End Sub

Function fcnValidate(oCtrl As Control, strValType As String) As Boolean
  fcnValidate = True
  Select Case strValType
    Case "Number"
      If Not IsNumeric(oCtrl.Text) Then
        MsgBox ("Must be a Number")
        With oCtrl
          .SetFocus
          .SelStart = 0
          .SelLength = Len(.Text)
        End With
        fcnValidate = False
      Else
        oCtrl.BackColor = vbWhite
      End If
    Case "Text"
  End Select
End Function
Reply With Quote