I have a large Excel sheet auto generated from C#, which outputs all columns as text (this cannot be changed for technical reasons). I am having trouble writing a macro which will convert the numeric columns to numbers, and do it fast (the sheet contains 80 columns and 20,000 rows).
I have tried iterating over all cells and calling
If IsNumeric(cell.Value) Then cell.Value = CDec(cell.Value)
This is very slow AND has the additional problem that I have a special case where strings starting with things such as “0xxx” need to be kept as a string. If I used IsNumeric and then convert to CDec, I LOSE the leading 0!
Is there some simple trick to say detect if one value in a column is a string, then do NOT process the column, else convert them to numeric EXCEPT for the case where we have a leading 0?
Does storing the value in memory and doing your checking work? Something similar to the below code, but you would have to refine it and replace
condition_is_truefor something meaningful. I would use a function to return back a boolean.