Validate textbox on userform

bisel

Board Regular
Joined
Jan 4, 2010
Messages
227
Office Version
  1. 365
Platform
  1. Windows
Hello All,

I have been searching and have found several topics on validating textboxes on userforms, but have not been able to find an answer and hoping someone can assist.

I have a userform with several textboxes. In my instance, I have a textbox that the user enters a year. I need to be sure that the year entered is equal to or greater than a year in a specific cell on the worksheet. If the year is less than that year, I want to capture that occurrence, display an error msg, delete the user's entry and set focus back on that text box.

I have tried this ...

Code:
Private Sub dues2_yearstextbox_AfterUpdate()

If dues2_yearstextbox.Value < Range("incr2_earlystart").Value Then
     MsgBox "Please enter a value less than or equal to the earliest start year."
        dues2_yearstextbox.Value = ""
        dues2_yearstextbox.SetFocus
        Else: End If
        
Application.Run ("update_controlpanel")

End Sub

But that does not work. I use the AfterUpdate event because I want to run the application "update_controlpanel" after the user updates the textbox ... that macro updates several userform labels.

The cell range, "incr2_earlystart", contain the 4-digit numeric field for the year I am trying validate against.

I did try the textbox event "Change" ... but that did not work either.

Appreciate any assistance.

Thanks,

Steve
 
Last edited:
Do you still have the
Code:
Private Sub dues2_yearstextbox_AfterUpdate()
code in there? if so try commenting it out.
 
Upvote 0

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,216,246
Messages
6,129,700
Members
449,528
Latest member
Paula03

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