Solved

Run time error on DirectPrecedents.Select

Posted on 2013-06-13
4
602 Views
Last Modified: 2013-06-13
Hello

I am struggling with my error handling in VBA (please refer below for an extract of code).

       Worksheet.Cells.Select

       On Error GoTo NoPrecedentCells
       Selection.DirectPrecedents.Select

NoPrecedentCells:

End Sub

Regardless of the "On Error" command, a run-time error 1004 (No cells were found) arises.

Can you assist in anyway.

Thanks and regards
Aidan
0
Comment
Question by:a_norton
  • 2
  • 2
4 Comments
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 39243777
Hi,

Have you verified in the VBE Options/ General  your Error Trapping Status

Break on All errors OR Break in Class Module OR Break on Unhandled Errors ( the right one)

Regards
0
 

Author Comment

by:a_norton
ID: 39243812
Hello,

My Error Trapping Status appears to be set to Break on Unhandled Errors...

Is this correct?  On this setting the problem does however persist :(
0
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39244288
Pls try

Sub DoIt()
ActiveSheet.Cells.Select
On Error Resume Next
PredCount = Selection.Precedents.Count
On Error GoTo 0
If PredCount = Empty Then
    GoTo NoPrecedentCells
Else
    Selection.DirectPrecedents.Select
End If
NoPrecedentCells:
End Sub

Open in new window

Regards
0
 

Author Closing Comment

by:a_norton
ID: 39244376
Thanks you so much!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now