code show warning message about brands

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,429
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
hello
i have data in sheet1 begins range from a2:c10 and userform contains 3 textbox the column c contain values when i fill data in textbox3 and press enter i would show the message " avalible is 200 or 300 or500.etc if the entered number in textbo3 more than what in column c
my code doesn't work well it gives me the first value in c in every time i choose specific brand
for in stance
my data in sheet:
a b c
ITEMBRANDQUNTITY
11200R20200
2315/80R22.5300
31400R20100

<tbody>
</tbody>

i fill these data in textbox1,2,3
textbox1= a , textbox2=b textbox3=c
it suppose when i fill the brand in textbox2 = "1200r20" and the quantity textbox3 ="500" then gives me the message " availible is 200" and so the rest the brands
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try this

Code:
Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  Dim f As Range
  If TextBox2.Value = "" Then
    MsgBox "Enter Brand"
    TextBox2.SetFocus
    Exit Sub
  End If
  If TextBox3.Value = "" Then Exit Sub
  If TextBox3.Value <= 0 Or Not IsNumeric(TextBox3.Value) Then
    Cancel = True
    MsgBox "Enter a valid value"
    Exit Sub
  End If
  Set f = Sheets("Data").Range("B:B").Find(TextBox2, , xlValues, xlWhole)
  If Not f Is Nothing Then
    If f.Offset(, 1) < Val(TextBox3) Then
      MsgBox "Available is : " & f.Offset(, 1)
      Cancel = True
    Else
      MsgBox "ok"
    End If
  Else
    MsgBox "Brand does not exists"
    TextBox2.SetFocus
  End If
End Sub
 
Upvote 0
Try this

Code:
Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  Dim f As Range
  If TextBox2.Value = "" Then
    MsgBox "Enter Brand"
    TextBox2.SetFocus
    Exit Sub
  End If
  If TextBox3.Value = "" Then Exit Sub
  If TextBox3.Value <= 0 Or Not IsNumeric(TextBox3.Value) Then
    Cancel = True
    MsgBox "Enter a valid value"
    Exit Sub
  End If
  Set f = Sheets("Data").Range("B:B").Find(TextBox2, , xlValues, xlWhole)
  If Not f Is Nothing Then
    If f.Offset(, 1) < Val(TextBox3) Then
      MsgBox "Available is : " & f.Offset(, 1)
      Cancel = True
    Else
      MsgBox "ok"
    End If
  Else
    MsgBox "Brand does not exists"
    TextBox2.SetFocus
  End If
End Sub

thanks a lot your code works perfect
 
Upvote 0
Glad to help you, thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,698
Members
448,979
Latest member
DET4492

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