Format a Double to have one decimal place number?

E

Ed

I am putting a value from an Excel cell into a Double variable, then
transferring that into a Word table. The Excel cells are formatted to
always show the value with one decimal place. But when I put the
value into the variable, if the actual number in the cell didn't have
a decimal, I don't show a decimal place when the number goes into
Word.

I'm trying to use
numData = Round(rng.Value, 1)
numData = Format(numData, "000000.0")
but the Format doesn't seem to do the job. How can I do this?

Ed
 
G

Guest

The Format function returns a string. When this is assigned to numData
(declared as double), VBA converts the string back to an actual number
(negating your intended purpose of using Format).

Perhaps you can format the number when you are putting it into word and not
when you are assigning it to your variable.

Format(numData, "0.0")

Or, perhaps declare numData as a string.
 
E

Ed

Or use rng.Text instead, then no formatting required.

rng.Text solved the whole problem! Thank you, Nick.

JMB:

Thanks for pointing out the string return from Format. I totally
missed that, and it would then make sense that putting it into a
numeric variable would change it back. I think remembering that may
save me some hours of frustration down the road!

Thanks to both of you for helping.
Ed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top