0 votes
in VBA by Expert (892 points)
Hello everyone

I am confused of how to use True and False in the sum process ...

I mean for example: In the immediate window if I typed 2 + True I got 1 >> I expect to get three as True equals to 1 but I got 1

At the same time I tried in the immediate window to type 2 + False and I got 2 >> and this is logical for me as False equals to 0 so 2 + 0 = 2


Any idea?

2 Answers

0 votes
by Expert (892 points)
selected by
Best answer

I have searched and found this link


It seems that True equals to -1 in VBA not equals to 1 as in using it in worksheet. So it is now logical for me

by Super Expert (3.2k points)
That is correct! Although it's atypical, the Boolean True equals -1 in VBA, VB.NET and Visual Basic
by Expert (892 points)
Thank you very much my tutor.
+2 votes
by Beginner (35 points)
I had to do something similar a while back and found that using Abs(True) fixed the issue for me. That gave me the value of +1 that I needed.
by Skilled (477 points)
The currently selected answer explains WHY the behavior exists, but I like this practical answer better. :)

Probably because I do the same thing!



Welcome to wellsr Q&A
wellsr Q&A is the VBA and Python programming community that rewards you for learning how to code.

Getting Started
VBA Cheat Sheets (On Sale Now)

Earn free prizes for asking VBA and Python questions and for answering questions asked by others in our community.

Looking for something else? Hire our professional VBA Help, instead.

What makes us different?
Our points system rewards you with a chance for free gifts based on the quality of your questions and answers. All you have to do is post and you could get rewarded, like these members:

ParserMonster $25 Amazon Gift Card
Hightree $10 Amazon Gift Card
Thales1 $10 Amazon Gift Card
runfunke $10 Amazon Gift Card
coolag $10 Amazon Gift Card
Siew Hun $10 Amazon Gift Card

So, why don't you join us? It really is an encouraging way to motivate members in our VBA and Python community.


For more programming tips visit the VBA Tutorials Blog and the Python Tutorials Blog.