Click to See Complete Forum and Search --> : [RESOLVED] format excel cell for 2 decimal places
wizkid
Feb 21st, 2006, 06:33 AM
I want to put some value in to my excel worksheet cell.
i want to format the cell to display only for 2 decimal places
for example
dim s as long
s=1.236767
.Cells(1, 4).Value = s
so i want the value for .Cells(1, 4).Value should be 1.23
how can i format this??i am using late binding
thanks
wizkid
direktoren
Feb 21st, 2006, 06:46 AM
I'm not sure I'm understanding your question correctly, but if I am, then you want 2 decimal spaces in a given range right?
In that case, just use the numberformat
range(yourrangehere).NumberFormat = "###,##0.00"
if you add another 0(zero) you get 3 decimal spaces - by removing the ,(comma) you won't get a 1.000 separator.
Hope this helps
/Nick
wizkid
Feb 21st, 2006, 06:51 AM
already i tried with this
but it is not working.i am getting error like property not valid
direktoren
Feb 21st, 2006, 06:54 AM
Can i see you code?
I normally use numberformat, but I haven't experienced errors
wizkid
Feb 21st, 2006, 07:02 AM
thanks direktoren
i got the answer
formatnumber is the property to format the number.
.Cells(stylecode_colorcode, 4).Value = FormatNumber(percen, 3)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.