SpecialCells(xlCellTypeFormulas)

K

Kevin Gabbert

Hi guys. I'm looking for a way to keep the following line:

Set oRange = oSheet.Cells.SpecialCells(xlCellTypeFormulas)


from returning an error.

I do know that a similar line of code:

Set oRange = oSheet.Cells.SpecialCells(xlCellTypeBlanks)

can be kept from raising an error if I use the following undocumented excel feature:

x = oSheet.Application.CountBlank(oRange)


...is there a similar one for xlCellTypeFormulas?

-K
 
T

Tom Ogilvy

If no cells meet the criteria, then specialcells returns an error.

The general approach is to trap the error.

Dim oRange as Range
On Error Resume Next
Set oRange = oSheet.Cells.SpecialCells(xlCellTypeFormulas)
On Error goto 0
if not oRange is Nothing then
' cells were found meeting the criteria
else
' cells were not found meeting the criteria
End if
 
Top