I have some calculated values that depend on a selected range. I want to format these calculated values with the NumberFormat of the selected range. I'm assuming they all have the same NumberFormat so I just take the numberformat of the first cell.
I am currently using the NumberFormat as follows:
columnFormat = cell.NumberFormat
stringNum = cstr(format(doubleNum, columnFormat)
Unfortunately, it doesn't work in a lot of cases, like when the format is "General" or a rather complex one we use that works fine in the cell but shows positive numbers ending with a "_)".
Is there a more robust way to do this? Do I have to have a big list of exceptions to check for?
You could use the WorksheetFunction.Text to do this (note this will be a little slower than using Format):
Richard
Open in new window