View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson[_4_] Jim Thomlinson[_4_] is offline
external usenet poster
 
Posts: 1,119
Default how error-trap "no cells were found error"

Try this..

Dim rngToSum As Range
Dim dSum As Double

Set rngToSum = Selection.SpecialCells(xlVisible)

If rngToSum Is Nothing Then
dSum = 0
Else
dSum = Application.Sum(rngToSum)
End If

--
HTH...

Jim Thomlinson


"Ian Elliott" wrote:

Thanks for any help.
I have some code in my macro:
dSum = Application.Sum(Selection.SpecialCells(xlVisible))
but if there is nothing selected (at least visibly selected), I get an error
"Run-time error '1004': No cells selected."
Is there some kind of IF, like IF (Application.Sum...)=NULL or something so
my program doesn't terminate?
Thanks