code show warning message about brands

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,494
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
[TABLE="width: 307"]
<tbody>[TR]
[TD]ITEM[/TD]
[TD]BRAND[/TD]
[TD]QUNTITY[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1200R20[/TD]
[TD]200[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]315/80R22.5[/TD]
[TD]300[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]1400R20[/TD]
[TD]100
[/TD]
[/TR]
</tbody>[/TABLE]

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

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
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
Solution
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

Forum statistics

Threads
1,223,903
Messages
6,175,279
Members
452,630
Latest member
OdubiYouth

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