Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,059
Default 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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,059
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lock Cell Format - Allow copy and paste of data without format change Chris12InKC Excel Worksheet Functions 2 May 9th 23 07:42 PM
Change cell colour on formula result change, no conditional format roster_jon Excel Programming 0 December 2nd 08 12:11 PM
assigning values to one cell which will change the formula in anot Darren Excel Worksheet Functions 1 July 26th 07 10:06 AM
Can cell format come from and change with reference cell format jclouse Excel Discussion (Misc queries) 1 November 29th 06 03:20 AM
Change default path for assigning macros AuthorizedUser Setting up and Configuration of Excel 1 January 30th 05 07:06 PM


All times are GMT +1. The time now is 09:41 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"