Yesterday one person asked that how can we run a business validation in Excel? I have given below example and same I sharing with you all.
In last post of VBA we have learnt "How to add two numbers via VBA" now what if I change the situation and mention that if Excel Cell values are empty system should run the business validation and display an error message if user is not passing any values in Cell.
We will follow below steps to check whether user is passing the values or not.
Sub Button1_Click()
If Len(Range("I7").Value) = "0" Then //Check the length of Cell I7
MsgBox ("Please Enter Value in Cell I7") //Display warning message to User
Exit Sub//Block the statement until above condition does not pass the validation
End If
If Len(Range("I8").Value) = "0" Then//Check the length of Cell I8
MsgBox ("Please Enter Value in Cell I8")//Display warning message to User
Exit Sub//Block the statement until above condition does not pass the validation
End If
Range("I9").Value = Range("I7").Value + Range("I8").Value
Len - Function return the length of specified string.
MsgBox - Displays a message in dialog box, wait for user to click the button
As a basic concept we are checking the length of particular cell and making an If condition.
Now this helps user to run the basic validations in Excel.
Keep Learning
Sanjay
mesanjaybakshi@gmail.com
In last post of VBA we have learnt "How to add two numbers via VBA" now what if I change the situation and mention that if Excel Cell values are empty system should run the business validation and display an error message if user is not passing any values in Cell.
We will follow below steps to check whether user is passing the values or not.
Sub Button1_Click()
If Len(Range("I7").Value) = "0" Then //Check the length of Cell I7
MsgBox ("Please Enter Value in Cell I7") //Display warning message to User
Exit Sub//Block the statement until above condition does not pass the validation
End If
If Len(Range("I8").Value) = "0" Then//Check the length of Cell I8
MsgBox ("Please Enter Value in Cell I8")//Display warning message to User
Exit Sub//Block the statement until above condition does not pass the validation
End If
Range("I9").Value = Range("I7").Value + Range("I8").Value
Len - Function return the length of specified string.
MsgBox - Displays a message in dialog box, wait for user to click the button
As a basic concept we are checking the length of particular cell and making an If condition.
Now this helps user to run the basic validations in Excel.
Keep Learning
Sanjay
mesanjaybakshi@gmail.com
No comments:
Post a Comment