Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

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

Avatar of jnash67
jnash67 asked on
Microsoft ExcelVisual Basic.NET
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?
Avatar of RichardSchollar
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answers