Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Ensuring a cell is copied in text format

I have a macro that uses the following code to copy the value from
the named range "a" to the named range "b" in another workbook:

a.Formula = a.Value2
a.Copy b

The problem is that the "b" cell gets formatted as Date, even though
it's preformatted as Text and the "a" cell also is formatted as Text.
(The "a" cell contains text like 11/2004, so the value is interpreted
as a date on arrival.)

I need to ensure that the "b" cell is formatted as Text, and that it
doesn't convert the original text to a "date number" like 38292. How
can this be done??
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Ensuring a cell is copied in text format

Hi

One way:
b.Value = "'" & a.Text

HTH. Best wishes Harald

"Richard H" skrev i melding
9...
I have a macro that uses the following code to copy the value from
the named range "a" to the named range "b" in another workbook:

a.Formula = a.Value2
a.Copy b

The problem is that the "b" cell gets formatted as Date, even though
it's preformatted as Text and the "a" cell also is formatted as Text.
(The "a" cell contains text like 11/2004, so the value is interpreted
as a date on arrival.)

I need to ensure that the "b" cell is formatted as Text, and that it
doesn't convert the original text to a "date number" like 38292. How
can this be done??



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Ensuring a cell is copied in text format

Worked beautifully! Takk skal du ha, Harald.

One minor problem, though: The "date" cell is formatted as text in
the original workbook, and written like this:

12/2004

On import, the data is converted to a standard date format, like
this:

Dec.04.

The code you supplied ensures that this is converted to text -
'Dec.04. I would preferably retain 12/2004, as originally entered.
Is that possible??

Richard


"Harald Staff" wrote in
:

Hi

One way:
b.Value = "'" & a.Text

HTH. Best wishes Harald

"Richard H" skrev i melding
9...
I have a macro that uses the following code to copy the value
from the named range "a" to the named range "b" in another
workbook:

a.Formula = a.Value2
a.Copy b

The problem is that the "b" cell gets formatted as Date, even
though it's preformatted as Text and the "a" cell also is
formatted as Text. (The "a" cell contains text like 11/2004, so
the value is interpreted as a date on arrival.)

I need to ensure that the "b" cell is formatted as Text, and
that it doesn't convert the original text to a "date number"
like 38292. How can this be done??

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Ensuring a cell is copied in text format

I'm not sure I understood this. When it comes to dates, the original entry
isn't there anymore. Excel converts it to a date immediately. But if mm/yyyy
is what you need, and a contains a real date, then for text
b.Value = "'" & Format$(a.Value, "mm/yyyy")
or, if you want the date to follow
b.Value = a.Value
b.NumberFormat = "mm/yyyy"

A cell can contain a date and display almost whatever. If it's a date then
it shows a real date in the formula bar. If formula bar also says
Dec 04
or
12/2004
then it's text, not a date.

HTH. Best wishes Harald

"Richard H" skrev i melding
1...
Worked beautifully! Takk skal du ha, Harald.

One minor problem, though: The "date" cell is formatted as text in
the original workbook, and written like this:

12/2004

On import, the data is converted to a standard date format, like
this:

Dec.04.

The code you supplied ensures that this is converted to text -
'Dec.04. I would preferably retain 12/2004, as originally entered.
Is that possible??

Richard


"Harald Staff" wrote in
:

Hi

One way:
b.Value = "'" & a.Text

HTH. Best wishes Harald

"Richard H" skrev i melding
9...
I have a macro that uses the following code to copy the value
from the named range "a" to the named range "b" in another
workbook:

a.Formula = a.Value2
a.Copy b

The problem is that the "b" cell gets formatted as Date, even
though it's preformatted as Text and the "a" cell also is
formatted as Text. (The "a" cell contains text like 11/2004, so
the value is interpreted as a date on arrival.)

I need to ensure that the "b" cell is formatted as Text, and
that it doesn't convert the original text to a "date number"
like 38292. How can this be done??



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Ensuring a cell is copied in text format

Harald,

you understood, alright. The only puzzling thing now is that the
imported "date" is converted to

'12.2004

even though your code

b.Value = "'" & Format$(a.Value, "mm/yyyy")

definitely tells Excel to return '12/2004.

I can't figure that one out, but I can live comfortably with it.
Thank you!

Regards,
Richard



"Harald Staff" wrote in
:

I'm not sure I understood this. When it comes to dates, the
original entry isn't there anymore. Excel converts it to a date
immediately. But if mm/yyyy is what you need, and a contains a
real date, then for text b.Value = "'" & Format$(a.Value,
"mm/yyyy") or, if you want the date to follow
b.Value = a.Value
b.NumberFormat = "mm/yyyy"

A cell can contain a date and display almost whatever. If it's a
date then it shows a real date in the formula bar. If formula
bar also says Dec 04
or
12/2004
then it's text, not a date.

HTH. Best wishes Harald

"Richard H" skrev i melding
1...
Worked beautifully! Takk skal du ha, Harald.

One minor problem, though: The "date" cell is formatted as text
in the original workbook, and written like this:

12/2004

On import, the data is converted to a standard date format,
like this:

Dec.04.

The code you supplied ensures that this is converted to text -
'Dec.04. I would preferably retain 12/2004, as originally
entered. Is that possible??

Richard


"Harald Staff" wrote in
:

Hi

One way:
b.Value = "'" & a.Text

HTH. Best wishes Harald

"Richard H" skrev i melding
9...
I have a macro that uses the following code to copy the
value from the named range "a" to the named range "b" in
another workbook:

a.Formula = a.Value2
a.Copy b

The problem is that the "b" cell gets formatted as Date,
even though it's preformatted as Text and the "a" cell also
is formatted as Text. (The "a" cell contains text like
11/2004, so the value is interpreted as a date on arrival.)

I need to ensure that the "b" cell is formatted as Text, and
that it doesn't convert the original text to a "date number"
like 38292. How can this be done??





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
paste copied text to only one cell Chris Excel Discussion (Misc queries) 5 November 6th 07 08:32 AM
Time format in a cell getting copied automatically into another ce Sasikiran Excel Discussion (Misc queries) 4 August 23rd 07 06:20 AM
cell format changes when formula copied? Todd Excel Worksheet Functions 1 April 14th 06 09:33 PM
format cell to change color when copied tawnee jamison Excel Discussion (Misc queries) 1 February 16th 05 08:55 PM
Why my cell format is not copied when I copied workbook? courtesio99[_28_] Excel Programming 0 January 9th 04 07:03 AM


All times are GMT +1. The time now is 05:22 PM.

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"