Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can't catch an error with on error operaror

Sub TextToNum()
Dim af As Double
For Each x In Selection
On Error GoTo 10
af = x.Value 'here appears error
x.NumberFormat = Number
On Error GoTo -1
x.Value = af
10 Next x
End Sub

If the value of the cell can’t be converted to number (letters, symbols) then there appears the error message and macros stops executing. Pass this error via On Error fails -the error message appears any way. How to solve this?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can use isNumber instead of error checking:

Sub TextToNum()
Dim af As Double
Dim x As Range
For Each x In Selection
    If IsNumeric(x.Value) Then
        af = x.Value
        x.NumberFormat = Number
        x.Value = af
    End If
Next x
End Sub

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading