![]() |
Runtime error 1004
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 |
Runtime error 1004
Sub noprecedents()
On Error GoTo nomo Selection.DirectPrecedents.Select nomo: End Sub -- Don Guillett Microsoft MVP Excel SalesAid Software "IgorM" wrote in message ... 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 |
Runtime error 1004
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. -- HTH... Jim Thomlinson "IgorM" wrote: 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 |
Runtime error 1004
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" napisał w wiadomości ... 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. -- HTH... Jim Thomlinson "IgorM" wrote: 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 |
All times are GMT +1. The time now is 09:23 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com