views:

1654

answers:

2

hi i am using c# to do things in excel-2007, i have the below code

   object mis = Type.Missing;
   Excel.Workbook wb = (Excel.Workbook)Globals.ThisAddIn.GetActiveWorkbook();
   Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets.Add(mis, mis, mis, mis);
   Excel.Range range = (Excel.Range)ws.get_Range("A1", "HM232");
   range.Formula = "Sheet4!A1:HM232*0.56+Sheet5!A1:HM232*0.45";
   range.NumberFormat = "0";

it correctly shows all the cells as whole decimal numbers without any decimal points... but know if i request the let's say, in cell G5 i see 1, but when i do the following

  MsgBox Range("G5").Value2

it shows me 0.933333222, how to make it so that the Value2 is also changed by the value rounded....?

A: 

I know in the prior to 2007 the NumberFormat property has had issues when different regional settings from US English are applied. Try using:

range.NumberFormatLocal = "0";
James
it still does not work
A: 

You could just convert the value to an Integer that would ensure it gets rounded to the nearest whole number e.g.

MsgBox Convert.ToInt32(Range.("G5").Value2)
James