Thread: empty range?
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default empty range?

Yes, it is annoying that it errors out if no cells are found (I think it is
doing this because it is a method and not a property). Anyway, I'm not sure
I know exactly what you are after, but maybe this code snippet will help...

On Error Resume Next
HowManyBlanks = Range("A1:A20").SpecialCells(xlCellTypeFormulas).C ount
On Error GoTo 0

If you Dim the variable HowManyBlanks as Long, then it will equal 0 if no
cells are found by the SpecialCells method and it will equal the actual
count otherwise. If you do not Dim the variable, then it will be a Variant
by default and its value would end up being Empty if SpecialCells returned
no cells.

--
Rick (MVP - Excel)


"sali" wrote in message
...
just as little surprise, method specialcells(xlCellTypeFormulas) had to
return "empty" range since there were no formulas, but instead of having
.cells.count=0, or to skip loop in "for each", it thrown error "no cells
in the range"

is it expected? i had to handle it with error goto, but would be nice to
handle it with count=0
this is excel 2000 vba

am i doing wrong, or there is realy no other way than throwing error?

thnx