PDA

View Full Version : check for errors



lior03
01-07-2008, 02:16 AM
hello
this code loops through every cell in used range detects error and report both the cell address(errored cells only)and the type of error.

Dim cell As Range
For Each cell In ActiveSheet.UsedRange
If IsError(cell) Then
MsgBox cell.Address & " - contain error" & CVErr(cell), vbInformation, "error handler"
End If
Next


how can i tell the user the type of error hehas through vba?
thanks

Bob Phillips
01-07-2008, 02:46 AM
Dim cell As Range
For Each cell In ActiveSheet.UsedRange
If IsError(cell) Then
MsgBox cell.Address & " - contain error" & cell.Text, vbInformation, "error handler"
End If
Next

lior03
01-07-2008, 10:15 PM
hello
i wanted to add another condition to an error cell - a formula cell with a zero.

Dim cell As Range
For Each cell In ActiveSheet.UsedRange
If Val(cell.HasFormula) = 0 Then
cell.Font.ColorIndex = 3
End If
Next


how can i denote all cells that have a formula and it's result is zero?
thanks

mikerickson
01-07-2008, 10:31 PM
Dim cell As Range
For Each cell In ActiveSheet.Cells.SpecialCells(xlCellTypeFormulas, xlNumbers)
If cell.Value = 0 Then
cell.Font.ColorIndex = 3
End If
Next