Combination of Minus and Equal signs

  • Thread starter Thread starter Syed Zeeshan Haider
  • Start date Start date
S

Syed Zeeshan Haider

Hello Experts,
I have Excel 97 Pro on Win98SE.

I have copied a function from http://www.cpearson.com/excel/colors.htm,
which contains following code as its part:

If OfText = True Then
CountByColor = CountByColor - _
(Rng.Font.ColorIndex = WhatColorIndex)
Else
CountByColor = CountByColor - _
(Rng.Interior.ColorIndex = WhatColorIndex)
End If

Now I cannot understand subtracting an equality as in:
CountByColor - _
(Rng.Font.ColorIndex = WhatColorIndex)

Does this mean "subtract if equal"?
Or does it have some other explanation?

Thank you,
 
Hi
in VBA the bollean value TRUE is represented by '-1' (FALSE = 0). So
subtracting a boolean value in VBA will actually add '1' to the Count
if the condition is met
 
Syed,

A comparison operation returns either TRUE or FALSE, which are
equivalent to -1 and 0, respectively. Therefore, subtracting the
result of a comparison is the same as subtracting -1 or 0, which
is the same as adding +1 or 0.

Note that TRUE in VBA is -1 while TRUE in Excel (worksheet
functions) is +1.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top