How to write Less Than Validation

Fahad Saleem

New Member
Joined
Mar 30, 2020
Messages
6
Office Version
  1. 2016
Platform
  1. Windows
Hi everyone,

anyone here, please tell me how can I validate text box value to be not less than second text box value. I mean to say, I want that the value of txt_Sale_Price box should not be less than the value of txt_Purchase_Price.
Please help me in this regard with code example
Thanks
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I show you 2 examples, one in the textbox event and the other with a commandbutton:

VBA Code:
Private Sub CommandButton1_Click()
  If Val(txt_Sale_Price) < Val(txt_Purchase_Price) Then
    MsgBox "txt_Sale_Price box should not be less than the value of txt_Purchase_Price"
    txt_Sale_Price.SetFocus
    exit sub
  End If
End Sub

Private Sub txt_Sale_Price_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  If Val(txt_Sale_Price) < Val(txt_Purchase_Price) Then
    MsgBox "txt_Sale_Price box should not be less than the value of txt_Purchase_Price"
    txt_Sale_Price.SetFocus
    Cancel = True
  End If
End Sub
 
Upvote 0
Glad to help you, thanks for the feedback.
 
Upvote 0
Sir I need more help in another case with code example.
I'm trying to develop Excel automated invoice generator with the help of vba. I made to 2 different userforms. First one is for customer information and second is for Item description etc. In second userform I want to code it like when I fill all the fields and press Add button, the data in this userform will go to the excel sheet row 15 and userform remain open and how much time I press Add button the data will go to the next row and than next. But whenever I start making Invoice the data adding will starts from Row 15.

Please help me in this regard. I will be very thankful to you.
 
Upvote 0
It is a different topic than this thread. I suggest you start a new thread. Explain in more detail, names of your controls, names of sheets, columns, etc.
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,148
Members
448,552
Latest member
WORKINGWITHNOLEADER

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