Consulting

Results 1 to 4 of 4

Thread: check for errors

  1. #1
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location

    check for errors

    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.
    [VBA]
    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

    [/VBA]
    how can i tell the user the type of error hehas through vba?
    thanks
    moshe

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    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
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location
    hello
    i wanted to add another condition to an error cell - a formula cell with a zero.
    [VBA]
    Dim cell As Range
    For Each cell In ActiveSheet.UsedRange
    If Val(cell.HasFormula) = 0 Then
    cell.Font.ColorIndex = 3
    End If
    Next

    [/VBA]
    how can i denote all cells that have a formula and it's result is zero?
    thanks
    moshe

  4. #4
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •