Help with UserForm textbox code

E

excelnut1954

I thought I posted this question last Friday. But, I can't find it.
Maybe I didn't actually finish posting it.....

I have deigned a UserForm that will allow the user to enter some info
that will be copied to a worksheet when the user clicks the OK button.
There are about a dozen fields the user will enter info to.

I have code that will look at the textbox1 entry, and compare it with
the data already in column J of this list, and warn the user if this
data already exists.. This works fine, except that I would like it to
identify this duplicate as soon as the user tabs out of textbox1. Right
now, it will perform this check only after the OK button is clicked,
when the whole UserForm is completed. I'd like to save the user from
entering in all the data that will not be copied to the list anyway.

Here is the current code to perform the check to find a duplicate when
it compares the textbox1 entry vs entries in column J of the worksheet:

With Worksheets("Official list")
If Application.CountIf(.Range("j:j"), TextBox1.Text) > 0 Then
MsgBox "This PO/PL is already on the list. Please edit the existing
record "
TextBox1.Text = Clear

Else

Range("J65536").End(xlUp)(2).Select
Application.Selection.Value = TextBox1.Text

End If

End With


Thanks for your help/suggestions.
J.O.
 
G

Guest

Hi,
Add this to the Uerform code:

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

With Worksheets("Official list")
If Application.CountIf(.Range("j:j"), TextBox1.Text) > 0 Then
MsgBox "This PO/PL is already on the list. Please edit the existing
Record """
TextBox1.Text = Clear

Else

Range("J65536").End(xlUp)(2).Select
Application.Selection.Value = TextBox1.Text

End If

End With

End Sub


HTH
 
E

excelnut1954

Thanks Toppers

I have a different twist of this problem. The problem you responded to,
I figured out. I had the coding in the wrong sub. I thought I removed
the post before anyone would respond to it.

HOWEVER
If you read my new entry I just entered, maybe you can help with this
problem.

Thanks,
J.O.
 
E

excelnut1954

Please see the new post Coding questions about UserForm TextBox.

I have this one all screwed up...

Thanks,
J.O.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top