troubleshooting Question

Excel VBA - Format a string with the NumberFormat of a cell

Avatar of jnash67
jnash67 asked on
Visual Basic.NETMicrosoft Excel
4 Comments1 Solution533 ViewsLast Modified:
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?
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros