View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
GB GB is offline
external usenet poster
 
Posts: 230
Default error convert to number macro

Well even so, I just took a blank cell, recorded a macro of setting the
Selection.NumberFormat = "0.00"

What I would do is loop through each cell in the desired range, if the text
of the cell isnumeric then select the cell and change the numberformat to the
desired format.
Ie.
For I = StartRow to EndRow
If IsNumeric(Application.Cells(I, ColumnLocation).Text) = true then
Application.Cells(I, ColumnLocation).NumberFormat = "0.00"
end if
Next I

I also did a little investigation about ensuring that the data in the cell
is actually numeric. If in the import it prepends the data with an
apostrophe, you can use the RIGHT function to work only with the portion of
the string that may or may not be numeric. You might also have to reset the
cells.value to your newly discovered "number" instead of the text present.

Some ideas, not perhaps a final answer, but somewhere to work from.
Maybe someone else can help you further?

Of course substituting
"cherrynich" wrote:

I tried that before I posted. You start recording and then convert one, then
stop recording and look at the code, and there isn't any code. Thank you
though.