Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Formatting number in VBA

I would like to have the result of the following line display with
only one
decimal place. As written, it consistently displays to five decimal
places. Obviously, because the output location is defined with a
variable, I can't
pre-format the cell it will be in. numQs and numWrong are Integers.
Cells(I + 2, "B").Formula = "=" & (numQs - numWrong) / numQs & "*100"
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Formatting number in VBA

With Cells(I + 2, "B")
.Formula = "=" & Format((numQs - numWrong) / numQs,"0.0") & "*100"

End With


Would be my guess at what you want.

Another interpretation might be:

With Cells(I + 2, "B")
.Formula = "=" & (numQs - numWrong) / numQs,"0.0" & "*100"
.NumberFormat:="#,##0.0"
End With

The first puts one decimal place in the formula, the second formats the cell
to only display one decimal place for the formula result.


--
Regards,
Tom Ogilvy




"John Pierce" wrote in message
om...
I would like to have the result of the following line display with
only one
decimal place. As written, it consistently displays to five decimal
places. Obviously, because the output location is defined with a
variable, I can't
pre-format the cell it will be in. numQs and numWrong are Integers.
Cells(I + 2, "B").Formula = "=" & (numQs - numWrong) / numQs & "*100"



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Formatting number in VBA

try something like this


Selection.NumberFormat = "0.0"



"John Pierce" wrote in message
om...
I would like to have the result of the following line display with
only one
decimal place. As written, it consistently displays to five decimal
places. Obviously, because the output location is defined with a
variable, I can't
pre-format the cell it will be in. numQs and numWrong are Integers.
Cells(I + 2, "B").Formula = "=" & (numQs - numWrong) / numQs & "*100"



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
number formatting Alex Excel Discussion (Misc queries) 3 June 4th 09 02:01 AM
number formatting Theresa Excel Discussion (Misc queries) 4 October 24th 08 08:25 PM
Formatting a number Michel Khennafi Excel Worksheet Functions 2 July 9th 07 05:42 PM
number formatting Sam Excel Worksheet Functions 4 January 10th 07 09:04 PM
formatting cell number based on previous cell number Pasquini Excel Discussion (Misc queries) 3 June 20th 06 06:36 AM


All times are GMT +1. The time now is 03:56 PM.

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"