Search code examples
excelvbaformatformula

How can I avoid or change the Error Format via VBA?


I have to export regularly from an external program an Excel table.

In this table, there are phone numbers in a list. Those exported numbers give me a kind of format error that can´t be fixed changing the format to "Standard" or "number", the only way that is accepted is when I click in the error box and press "convert to a number".

Format error

The issue comes because the formulas in my Macro won´t accept the format and I can´t let my co-workers change it manually.

Is there any way via VB to change the format of those cells automatically?

I tried in VB and also manually:

Selection.NumberFormat = "0.00"
Selection.NumberFormat = "General"

Solution

  • enter image description here

    Notice I've selected all those cells with numbers but being recognized as text (same case as yours). Then this code fix it:

    Selection.ClearFormats
    Selection = Selection.Value
    

    After executing code:

    enter image description here

    Now all values are being read as numeric (notice how aligment has changed)