Data Validation in User Form -erratic

AlanAnderson

Board Regular
Joined
Jun 7, 2010
Messages
134
Hi All,

I have the following data validation routine. I am getting erratic behaviour within my programme that seems somehow linked to this.
Is there a problem with this or should i be looking elsewhere?

Regards,

Alan

Code:
Private sub tbTaxYN_Change()_
If UCase (tbTaxYN) = "Y" or UCase (tbTaxYn) = "N" then
Goto EndProc:
Else
MsgBox "Please enter either a Y or a N"
End if
EndProc:
End sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi All,

I have the following data validation routine. I am getting erratic behaviour within my programme that seems somehow linked to this.
Is there a problem with this or should i be looking elsewhere?

Regards,

Alan

Code:
Private sub tbTaxYN_Change()_
If UCase (tbTaxYN) = "Y" or UCase (tbTaxYn) = "N" then
Goto EndProc:
Else
MsgBox "Please enter either a Y or a N"
End if
EndProc:
End sub


I might be wrong here but it looks like you are wanting to force a column data entry to be Y or N...

Wouldn't you be better (& easier) to highlight the entire column and use data > validation..?
 
Upvote 0
Hi. This would be simpler

Code:
Private Sub tbTaxYN_Change()
If UCase(tbTaxYn) <> "Y" And UCase(tbTaxYn) <> "N" Then
    MsgBox "Please enter either a Y or a N"
End If
End Sub
 
Upvote 0
Hi CharleyMax And Peter,
Charley - no I'm trying to force correct entry into a form.

Peter, thanks, that's a lot more elegant. I'll try it and see if it works.

Thanks,

Alan
 
Upvote 0
Hi Peter, Tried it but still have two issues:
1. It is displaying msgbox as form is displayed even though defaults in the field are correct.
2. If I type in rubbish (say q) it brings up msgbox but after pressing OK I can still go ahead and save the "q"

Any thoughts??

Regardsm

Alan
 
Upvote 0
Possibly

Code:
Private Sub tbTaxYN_Change()
Static iRun As Boolean
If iRun Then Exit Sub
If UCase(tbTaxYn) <> "Y" And UCase(tbTaxYn) <> "N" Then
    tbTaxYn.Text = ""
    MsgBox "Please enter either a Y or a N"
    iRun = True
Else
    iRun = False
End If
End Sub
 
Upvote 0
Hi Peter,

Thanks again for your help. I must have some other issue in my programme as I am still getting same problems. The logic in your routine is clearly not the problem.

Thanks again,

Alan
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,555
Members
452,928
Latest member
101blockchains

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