![]() |
Why does cell format change when assigning a value?
I have some VBA code which accumulates a total of several cells, then puts
that total into a cell formatted as "Accounting" format. Every time this code runs, it changes the cell formatting to "Currency". I have tested this with a new, blank workbook and I get the same result. Try the following: Sub test() a = 10 Cells(2, 1) = 0 a = a + Cells(2, 1) Cells(3, 1).Value = a End Sub Why does it change the formatting??? And how do get around this problem? -- N Selinger |
Why does cell format change when assigning a value?
"N Selinger" wrote:
I have some VBA code which accumulates a total of several cells, then puts that total into a cell formatted as "Accounting" format. Every time this code runs, it changes the cell formatting to "Currency". [....] And how do get around this problem? Try the following test code: Range("A2").Value2 = Range("A2") + 1 Note the use of Value2 instead of Value. Why does it change the formatting??? In Unix, we have a saying: "don't ask why" ;-). But the following might provide a hint: http://msdn.microsoft.com/en-us/libr...ffice.11).aspx . ----- original message ----- "N Selinger" wrote in message ... I have some VBA code which accumulates a total of several cells, then puts that total into a cell formatted as "Accounting" format. Every time this code runs, it changes the cell formatting to "Currency". I have tested this with a new, blank workbook and I get the same result. Try the following: Sub test() a = 10 Cells(2, 1) = 0 a = a + Cells(2, 1) Cells(3, 1).Value = a End Sub Why does it change the formatting??? And how do get around this problem? -- N Selinger |
Why does cell format change when assigning a value?
Let's try this again, this time with proper explanation....
"N Selinger" wrote: I have some VBA code which accumulates a total of several cells, then puts that total into a cell formatted as "Accounting" format. Every time this code runs, it changes the cell formatting to "Currency". [....] And how do get around this problem? Put a value into A2 and format A2 as Accounting. Then try the following test code: Range("A2").Value2 = Range("A2") + 1 Note the use of Value2 instead of Value. Why does it change the formatting??? In Unix, we have a saying: "don't ask why" ;-). But the following might provide a hint: http://msdn.microsoft.com/en-us/libr...ffice.11).aspx . ----- original message ----- "N Selinger" wrote in message ... I have some VBA code which accumulates a total of several cells, then puts that total into a cell formatted as "Accounting" format. Every time this code runs, it changes the cell formatting to "Currency". I have tested this with a new, blank workbook and I get the same result. Try the following: Sub test() a = 10 Cells(2, 1) = 0 a = a + Cells(2, 1) Cells(3, 1).Value = a End Sub Why does it change the formatting??? And how do get around this problem? -- N Selinger |
All times are GMT +1. The time now is 06:43 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com