empty range?
I'm not sure if you can do it with the Count Function but here are two ways
you can make your code work without an error being thrown and without using
On Error Goto statements.
Option 1:
Sub FindFormulas()
If IsNull(Sheets("Sheet1").Cells.HasFormula) Or
Sheets("Sheet1").Cells.HasFormula Then
MsgBox "Found Formulas"
' or your code here
End If
End Sub
or
Option 2:
Call the function FormulaFinder with your range you want to scan in the "(
)". For example,
Sub YourSub()
' check for formulas
If FormulaFinder(Range("A1:A100")) Then
' put your code here
End If
End Sub
Function FormulaFinder(myRange As Range) As Boolean
Dim rng As Range
For Each rng In myRange
If rng.HasFormula Then
FormulaFinder = True
Exit For
End If
Next rng
End Function
Hope this helps! If so, click "YES" below.
--
Cheers,
Ryan
"sali" wrote:
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
.
|