Search code examples
vbaexcelcell

How to resolve excel error 2029 with #NAME?


I read an excel file and on a cell I got a text like this:

"=- Bla Bla Bla". This will not be recognize and will show #NAME?

So if you need to read some cell and get it into database this error in the file will show as Error 2029. The script will freeze. So, can I pre-replace the content if I get = or - chars in the cell so I validate the content before I read it and get the error. Can I pass over it!

I need cell validation

Private Sub Worksheet_Change(ByVal Target As Range)
    c = Target.Cells.Column
    r = Target.Cells.Row
    'validate cell
End If

Thank you!


Solution

  • I got it working

    'verify cell for data
    Private Sub Worksheet_Change(ByVal Target As Range)
        c = Target.Cells.Column
        r = Target.Cells.Row
    
        If IsError(Target.Worksheet.Cells(r, c)) Then
            MsgBox "You have a validation Error!"
            Target.Worksheet.Cells(r, c) = ""
            End If
    End Sub