messagebox based on value userform

ryan_law2000

Well-known Member
Joined
Oct 2, 2007
Messages
738
In a userform I have textbox1
If this textbox = any number in column B Sheet1
then have a message box appear saying " repeat number"
then after pressing ok
delete the number from textbox1
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
You did not say what you want to have happen if the number is not in column B of Sheet1 so taking your question literally, and assuming what you are "pressing ok" to is CommandButton1, this will do what you ask:

Code:
Private Sub CommandButton1_Click()
Dim strText&, dblVal#, varFind As Variant
strText = TextBox1.Text
dblVal = Val(strText)
Set varFind = _
Sheets("Sheet1").Columns(2).Find(What:=dblVal, LookIn:=xlFormulas, LookAt:=xlWhole)
If Not varFind Is Nothing Then
MsgBox strText & " is a repeat number.", 64, "Duplicate"
TextBox1.Text = ""
End If
Set varFind = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,833
Members
452,947
Latest member
Gerry_F

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