MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Display decimal places

  Asked By: Rena    Date: Nov 09    Category: MS Office    Views: 827

I cannot get the decimal places from the following sub to display in
the cell:
Sub proCalcHalfLife()
'sets vars
Dim sglKel As Single
Dim sglHalfLife As Single
Dim vAnswer As String
Dim strHalfLife As String
'pulls vars from worksheet
sglKel = ActiveSheet.Cells(27, 2)
'calc t1/2
sglHalfLife = 0.693 / sglKel
'insert into worksheet
ActiveSheet.Cells(27, 8) = sglHalfLife
'show msg box with half-life
strHalfLife = sglHalfLife
vAnswer = MsgBox(Prompt:="The half-life is " & strHalfLife & "
hrs." _
, Buttons:=vbOKOnly, Title:="Half-Life")
'next sub
Load frmStartDose
End Sub

The message box displays the answer with decimal places, but the
value inserted into the cell shows as a whole number. The value in
the formula bar shows the number with 6 or 7 decimal places. No
matter what I've tried to change the formatting of the cell, it won't
display them. I have other cells that are displaying them properly,
but this one won't. Any ideas?



1 Answer Found

Answer #1    Answered By: Rachel Fischer     Answered On: Nov 09

I just plugged your exact code into a button click subroutine, commented out
the last two lines that show the form, put 1 into B27 and clicked the

The number put into H27 (as shown in the formula bar) is 0.693000018596649
and this is shown in the cell  itself as 0.693.

This was a brand new workbook in Excel 2003. Making column H wider showed
me up to a maximum of 9 decimal  places without changing the format. With
extreme narrowing, I could get it to show fewer decimal places.

Format of the cell is "General". If I change it to "Number", I get two DP,
and then can increase the number of displayed decimal places without

So ... no idea what you're trying, but it looks as though your cell is badly
formatted. Change it back to "General" and make it wide enough to see a
reasonable number of decimal places.

Didn't find what you were looking for? Find more on Display decimal places Or get search suggestion and latest updates.