Situatie
In Excel when we compare two cell contents or numbers by applying equal sign between them, we get output in TRUE or FALSE format. Which means values which we are comparing may be equal or may not be equal. In a similar manner, we have Boolean in VBA Excel.
Boolean also gives the output in the form of TRUE or FALSE. Boolean is a form of data type which can only contain either TRUE or FALSE. When we give some input to Boolean and if the test becomes TRUE then we get an answer as TRUE or we get FALSE.
Solutie
Pasi de urmat
- For that go to the VBA window and click on the Insert menu tab.
- From the list select a Module as shown below.
Now in the opened module, write the sub category of VBA Boolean. We can choose to write any name of subprocedure here.
Code: Sub VBABoolean1() End Sub
Now define a Dim with any name, let’ say an A and assign the variable A as Boolean as shown below.
Let’s consider two numbers, 1 and 2. And now we will test with the help of Boolean whether 2 is greater than 1 or not. So in the next line, write a mathematical expression of 1<2under defined variable A.
Now assign a message box to variable A to see what outcome will appear when we run the code.
For running the code, click on the Play button which is below the menu bar. As we can see, we got the output as TRUE which means 1 is less than 2.
Leave A Comment?