Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 65
Default Format a Double to have one decimal place number?

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Format a Double to have one decimal place number?

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.


"Ed" wrote:

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Format a Double to have one decimal place number?

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

NickHK

"Ed" wrote in message
ps.com...
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 65
Default Format a Double to have one decimal place number?

On Jun 26, 9:06 pm, "NickHK" wrote:
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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
A non roundup decimal place cell format Nakal Excel Discussion (Misc queries) 6 January 28th 08 07:04 PM
Subtracting two 2-decimal place numbers gives result 13-decimal places? [email protected] Excel Worksheet Functions 5 March 12th 07 10:38 PM
Decimal Number Format in ComboBox Drummer361 Excel Programming 3 August 6th 06 10:21 PM
Converting 2-place decimal value to floating point decimal number with leading zero Kermit Piper Excel Discussion (Misc queries) 3 March 18th 06 06:20 PM
Set default in Excel so each number entered has same decimal place Juana Cafe Setting up and Configuration of Excel 0 March 8th 05 11:21 PM


All times are GMT +1. The time now is 02:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"