Re: count occurences of font color



Not true. Your isnull test determines the need to loop or not. If it is
null, you loop. No difference there in approaches except the extra test.

If it isn't null, you check the font color of the range. In that case, my
checking the first character would stop the loop just as easily with no
additional looping..

For Each rCell In rRange.Cells
With rCell
For i = 1 To Len(.Value)
If .Characters(i, 1).Font.ColorIndex = iColor Then
n = n + 1
Exit For
End If
End If
End With
Next

Should be just as effective. No looping through xlautomatic except in the
same situations your original code. would. loop.

--
Regards,
Tom Ogilvy

"keepITcool" <xrrcvgpbby@xxxxxxxxx> wrote in message
news:xn0ei1xrjjhyd5001keepitcoolnl@xxxxxxxxxxxxxxxxxxxxx
Tom,

Not true. The null test is there to avoid the loop
when the cell(not partial text) is formatted.
in a likely scenario most cells will have
CELL.font.colorindex = xlAutomatic

and your code must loop all characters to find out.


--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Tom Ogilvy wrote :

You could ignore the Null test and just jump out when the first
matching color is found (as I suggested in my earlier answer). It
would work in either case.

ActiveCell.Font.ColorIndex = 41
? ActiveCell.Characters(1,1).Font.ColorIndex
41


.



Relevant Pages

  • Re: [KJ] [patch] fix common mistake in polling loops
    ... > Yes, Linus was wrong here. ... Or more precisely, he's right original code ... depending on use. ... Wouldn't this be better than adding a check after the break of loop? ...
    (Linux-Kernel)
  • Re: Moving window to show chart
    ... why the original code didn't work). ... Putting it ahead of the loop doesn't work. ... >This is in a standard module and screen updating is on, ...
    (microsoft.public.excel.programming)
  • Re: do..while statement in Matlab?
    ... from other programming language source. ... In same programs a DO/REPEAT or any LOOP structure with WHILE or UNTIL based ... Especially, due to the exit test at the end of the loop, the original code ... LET X=...of one extensive and sophisticate code ...
    (comp.soft-sys.matlab)
  • Re: Goslings quicksort freezes
    ... >> QSortAlgorithm does freeze. ... if you got an unlucky pick of the partitioning element ... > The loop is much different in Gosling's original code. ...
    (comp.lang.java.programmer)
  • Re: How to translate C++ for loop into VB.NET?
    ... Your original code seems like the loop should start at zero, ... Do you want this loop to simply increment by 1 each time it runs? ... But it's not the end of the world, and I can implement the translation ...
    (microsoft.public.dotnet.languages.vb)

Loading