Reuse text box validation code for multiple text boxes

zinzah

New Member
Joined
Mar 9, 2010
Messages
49
hi again...

I have a userform...with multiple frames...each containing multiple text boxes.
i am using this code to validate one text box in one part of my code
VBA Code:
Sub tbxEndGameNum_Change()
Debug.Print "tbxEndGameNum_Change()"


If Len(tbxEndGameNum) = 4 Then
'Application.ScreenUpdating = False

  If IsNumeric(tbxEndGameNum.Value) = False Or tbxEndGameNum.Value = vbNullString Then
        If (tbxEndGameNum.Value < 1300 Or tbxEndGameNum.Value > 2500) Then
            Selection = MsgBox("Please enter a valid 4 digit game number", 1, "INVALID GAME NUMBER!")
            tbxEndGameNum.Value = ""
            tbxEndGameNum.SetFocus
            Exit Sub
        End If
    Else
        MsgBox "Your input data is not valid"
        tbxEndGameNum.Value = ""
        tbxEndGameNum.SetFocus
        Exit Sub

End If

Call Processing
End If
End Sub

Wondering what i have to do/where do i need to move this/how do i change it so that i can call the same validations for all the textboxes when data in entered?
 
yours does work...with no issues.
I have a lot of confidential data in there. would take a while.....but i'll give it a shot....

ok...don't yell at me.... :)

The textbox is losing focus to a FRAME that it is in....
trying to figure that out...

And i'll still look into striping out anything i need to before sharing...
 
Upvote 0

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,223,964
Messages
6,175,657
Members
452,664
Latest member
alpserbetli

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top