View Full Version : Text String starts with "#"


RaunLGoode
06-01-2010, 11:54 AM
I have a sub that reads a cell value and stores it as a variable with a data type "String"
everything runs well until I hit a range with "#N/A" as the cell value.
This causes a type mismatch error

If I modify the cel value to "Number N/A" everything works just fine.
Is there some way to Trap the "# " character and modify it so the string doesn't cause an error?

Are there any other characters that will cause this type of error?

Brianwarnock
06-01-2010, 12:28 PM
I suppose any of the errors will cause a problem theoretically, but probably not all can occur.
The code below comes from VBA help in EXCEL and may help you.

This example displays a message if the active cell on Sheet1 contains a cell error value. You can use this example as a framework for a cell-error-value error handler.

Worksheets("Sheet1").Activate
If IsError(ActiveCell.Value) Then
errval = ActiveCell.Value
Select Case errval
Case CVErr(xlErrDiv0)
MsgBox "#DIV/0! error"
Case CVErr(xlErrNA)
MsgBox "#N/A error"
Case CVErr(xlErrName)
MsgBox "#NAME? error"
Case CVErr(xlErrNull)
MsgBox "#NULL! error"
Case CVErr(xlErrNum)
MsgBox "#NUM! error"
Case CVErr(xlErrRef)
MsgBox "#REF! error"
Case CVErr(xlErrValue)
MsgBox "#VALUE! error"
Case Else
MsgBox "This should never happen!!"
End Select
End If

Brian