View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default Find errors in Excel.

On Wed, 17 Feb 2010 11:16:08 +0100, "Jan Kronsell"
wrote:

I have this code:

Sub t()
For Each s In ActiveWorkbook.Sheets
For Each c In s.UsedRange.Cells
If IsError(c) Then
errval = c.Value
If errval = CVErr(xlErrRef) Then
c.Interior.ColorIndex = 3
End If
End If
Next c
Next s
End Sub

It colors all cells red, if the contains the #REF! error. The problem is,
that my client would like it to select the first instans of the error and
stop. When he runs it a second time, it should stop with the second instans
and so on.

I don't see how this can be done?

Jan



When you write "stop with the second instans" do you still want the first
instance colored?

If so:

======================================
ption Explicit
Sub t()
Dim s As Worksheet
Dim c As Range
For Each s In ActiveWorkbook.Sheets
For Each c In s.UsedRange.Cells
If IsError(c) Then
With c
If .Value = CVErr(xlErrRef) And _
.Interior.ColorIndex < 3 Then
.Interior.ColorIndex = 3
Exit Sub
End If
End With
End If
Next c
Next s
End Sub
====================================
--ron