Runtime error 1004

I

IgorM

Hi

When my macro tries to run the line below if the selected cell has no
formulas i get a runtime error 1004 - no cells were found. How to get around
this?

Selection.DirectPrecedents.Select

Kind regards
Igor
 
D

Don Guillett

Sub noprecedents()
On Error GoTo nomo
Selection.DirectPrecedents.Select
nomo:
End Sub
 
J

Jim Thomlinson

I would be inclined to do it this way...

dim rngPrecedents as range

on error resume next
set rngPrecedents = Selection.DirectPrecedents
on error goto 0

if rngPrecedents is nothing then
msgbox "sorry no precedents"
else
rngPrecedents.select
end if

It is a bit longer than Don's code (which works) but it does not leave you
in an error handler. My preference is to avoid errors were possible. If I
have to generate an error I try to dismiss it as soon as possible and resume
normal execution.
 
I

IgorM

I tried

Dim mrngPrecedents As Range
On Error Resume Next
Set mrngPrecedents = Selection.DirectPrecedents

But I still get the same error


U¿ytkownik "Jim Thomlinson" <[email protected]>
napisa³ w wiadomo¶ci
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top