Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello,
I have a macro which calculates the value of a currency variable and then using the statement ActiveCell.Offset(-1,7).Value = currTradeValue outputs it to a spreadsheet. The value is always rounded to 2 decimal points despite trying the following; 1. I have checked the value of the variable prior to the above statement being executed and it is as I expect - 3 decimal points e.g. -1.125 2. Formatted the target cell using ActiveCell.Offset(-1,7).NumberFormat = "#,##0.00_);[Red](#,##0.00)" prior to the assignment statement. 3. Manually formatted the cell within Excel prior to the assignment statement. 4. Checked the Online Help. If I have a cell that contains a 4 decimal point number for example and format the cell to round to 2 decimal points, and then select that cell, the number in the formula bar is the original 4 decimal point number. For some reason, the value of the currency variable seems to be modifed to 2 decimal points before being output as it is the modified value that I see in the formula bar when the cell in question is selected. Could someone please tell me what I or Excel is doing wrong. Thank you Mark. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
You can have as many decimal points as you want. Just increase the number of zeros afer the decimal point. The following gives you 3 decimal points. ActiveCell.Offset(-1, 7).NumberFormat = "#,##0.000;[Red]#,##0.000" Note: The first section is for a positive value and after the semi colon (;) is for a negative value. The above makes a negative value Red. Regards, OssieMac " wrote: Hello, I have a macro which calculates the value of a currency variable and then using the statement ActiveCell.Offset(-1,7).Value = currTradeValue outputs it to a spreadsheet. The value is always rounded to 2 decimal points despite trying the following; 1. I have checked the value of the variable prior to the above statement being executed and it is as I expect - 3 decimal points e.g. -1.125 2. Formatted the target cell using ActiveCell.Offset(-1,7).NumberFormat = "#,##0.00_);[Red](#,##0.00)" prior to the assignment statement. 3. Manually formatted the cell within Excel prior to the assignment statement. 4. Checked the Online Help. If I have a cell that contains a 4 decimal point number for example and format the cell to round to 2 decimal points, and then select that cell, the number in the formula bar is the original 4 decimal point number. For some reason, the value of the currency variable seems to be modifed to 2 decimal points before being output as it is the modified value that I see in the formula bar when the cell in question is selected. Could someone please tell me what I or Excel is doing wrong. Thank you Mark. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Just a little more info. When I format a cell with the code that I gave you
if I enter 2.655 then I get 2.66 displayed in the cell and in the formula bar is 2.655. If I multiple the cell contents by 2 then I get 5.31 which is 2.655 x 2. Tested above in both xl2002 and xl2007 Regards, OssieMac "OssieMac" wrote: Hi, You can have as many decimal points as you want. Just increase the number of zeros afer the decimal point. The following gives you 3 decimal points. ActiveCell.Offset(-1, 7).NumberFormat = "#,##0.000;[Red]#,##0.000" Note: The first section is for a positive value and after the semi colon (;) is for a negative value. The above makes a negative value Red. Regards, OssieMac " wrote: Hello, I have a macro which calculates the value of a currency variable and then using the statement ActiveCell.Offset(-1,7).Value = currTradeValue outputs it to a spreadsheet. The value is always rounded to 2 decimal points despite trying the following; 1. I have checked the value of the variable prior to the above statement being executed and it is as I expect - 3 decimal points e.g. -1.125 2. Formatted the target cell using ActiveCell.Offset(-1,7).NumberFormat = "#,##0.00_);[Red](#,##0.00)" prior to the assignment statement. 3. Manually formatted the cell within Excel prior to the assignment statement. 4. Checked the Online Help. If I have a cell that contains a 4 decimal point number for example and format the cell to round to 2 decimal points, and then select that cell, the number in the formula bar is the original 4 decimal point number. For some reason, the value of the currency variable seems to be modifed to 2 decimal points before being output as it is the modified value that I see in the formula bar when the cell in question is selected. Could someone please tell me what I or Excel is doing wrong. Thank you Mark. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi OssieMac,
I am using Excel 2003. I did modify the number format to include an extra digit, but based on my observation that the value is changed prior to it being written to the spreadsheet, I did not think this would make any difference and unfortunately it didn't. Bottom line is I think the value is changed before being output and no formatting is going to change it. Thanks for your help Mark |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Mark,
If you are still having problems then as Dave Peterson suggested, you may need to post more code so include all code where you create and/or manipulate the data to get the value in currTradeValue and we can have another look at it. Regards, OssieMac "MarkM" wrote: Hi OssieMac, I am using Excel 2003. I did modify the number format to include an extra digit, but based on my observation that the value is changed prior to it being written to the spreadsheet, I did not think this would make any difference and unfortunately it didn't. Bottom line is I think the value is changed before being output and no formatting is going to change it. Thanks for your help Mark |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Guys,
Dave suggested using Value2. Initially I did not use this as according to VBA Help, Value2 property doesn't use the Currency and Date data types, but I thought it best to try it before posting the code and to my surprise it actually works. Sorry I doubted you Dave. Thanks for you help Mark |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Decimal Points | New Users to Excel | |||
auto decimal in currency | Excel Worksheet Functions | |||
How can I convert decimal commas to decimal points? | Excel Discussion (Misc queries) | |||
Decimal Points | Excel Worksheet Functions | |||
decimal places in currency | Excel Programming |