Format DecimalPlaces in VB

  • Thread starter Thread starter Stephen.
  • Start date Start date
S

Stephen.

Hi all.

I run the following function in access (quite time
consuming)
ResultCalcfield= ExcelObject.WorksheetFunction.NormSInv(1 -
datafeild1/ datafeild2) + 1.5
but need the result to be formatted to 1st decimal place,
I have searched the help, but not really found anything
that useful.

Could anyone please assist?
 
Stephen,

After the function, you can either select the column or a
range of cells and use the NumberFormat command. It took
me awhile to find this myself. The intCT2 in the example
is the record count and formats only the cells I want.

ExcelObject.Worksheets("yoursheet").Range("i8:i" & intCT2
& 9).NumberFormat = "#,##0.0"

Or...the whole column.....

ExcelObject.Worksheets("yoursheet").Columns
("d").NumberFormat = "#,##0.0"
 
but need the result to be formatted to 1st decimal place,

.... or do it the oldfashioned way:

ResultCalField = Int(ResultCalcField * 10 + 0.5) * 0.10

HTH


Tim F
 
Back
Top