Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy Number Formats


I must be missing something obvious here... I am trying to use a rang
copy to copy values and formats from a series of worksheets. Th
values come over fine, but the number formats do not.

What is the trick to copy number formats? The vba is:
With sh.Range(sh.Cells(FirstRow, FirstCol)
sh.Cells(shLast, LastCol))
DestSh.Cells(Last + 1, 1).Resize(.Rows.Count, _
.Columns.Count).Value = .Value
DestSh.Cells(Last + 1, 1).Resize(.Rows.Count, _
.Columns.Count).NumberFormat = .NumberFormat
End With

Thanks,
Stev

--
Steve
-----------------------------------------------------------------------
SteveS's Profile: http://www.excelforum.com/member.php...fo&userid=1011
View this thread: http://www.excelforum.com/showthread.php?threadid=26838

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default Copy Number Formats

I expect the underlying problem is that in your source range, the number
format varies from one cell to another. In that situation, the .Numberformat
property returns NULL. It doesn't return an array of formats for each cell in
the range.

To demonstrate: put some data in, say A1:A3, and set different number formats
for at least one of the cells. Then select those cells, in the VBE immediate
window type ? Selection.Numberformat. You'll see that it prints NULL.

If the formats vary, and you want to replicate them, you'll have to do it a
cell at a time, or at least do it in "chunks" of cells, all of which have the
same number format.


On Mon, 11 Oct 2004 23:54:45 -0500, SteveS
wrote:


I must be missing something obvious here... I am trying to use a range
copy to copy values and formats from a series of worksheets. The
values come over fine, but the number formats do not.

What is the trick to copy number formats? The vba is:
With sh.Range(sh.Cells(FirstRow, FirstCol),
sh.Cells(shLast, LastCol))
DestSh.Cells(Last + 1, 1).Resize(.Rows.Count, _
Columns.Count).Value = .Value
DestSh.Cells(Last + 1, 1).Resize(.Rows.Count, _
Columns.Count).NumberFormat = .NumberFormat
End With

Thanks,
Steve


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default Copy Number Formats

PS: The interesting thing is that assigning a number format of NULL, as your
code is probably doing, doesn't cause a run-time error.

On Tue, 12 Oct 2004 00:12:28 -0500, Myrna Larson
wrote:

I expect the underlying problem is that in your source range, the number
format varies from one cell to another. In that situation, the .Numberformat
property returns NULL. It doesn't return an array of formats for each cell in
the range.

To demonstrate: put some data in, say A1:A3, and set different number formats
for at least one of the cells. Then select those cells, in the VBE immediate
window type ? Selection.Numberformat. You'll see that it prints NULL.

If the formats vary, and you want to replicate them, you'll have to do it a
cell at a time, or at least do it in "chunks" of cells, all of which have the
same number format.


On Mon, 11 Oct 2004 23:54:45 -0500, SteveS
wrote:


I must be missing something obvious here... I am trying to use a range
copy to copy values and formats from a series of worksheets. The
values come over fine, but the number formats do not.

What is the trick to copy number formats? The vba is:
With sh.Range(sh.Cells(FirstRow, FirstCol),
sh.Cells(shLast, LastCol))
DestSh.Cells(Last + 1, 1).Resize(.Rows.Count, _
Columns.Count).Value = .Value
DestSh.Cells(Last + 1, 1).Resize(.Rows.Count, _
Columns.Count).NumberFormat = .NumberFormat
End With

Thanks,
Steve


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Copy Number Formats

To OP:
If you're coding for xl2000+ then you could use:

rngSrc.Copy
rngDst.PasteSpecial xlPasteValuesAndNumberFormats

To Myrna:
assigning NULL or a mixed bag of numberformats throws exception in all
versions on my PC (as expected)

i did note that assigning EMPTY clear formats... (not surprisingly)




keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


Myrna Larson wrote:

PS: The interesting thing is that assigning a number format of NULL,
as your code is probably doing, doesn't cause a run-time error.

On Tue, 12 Oct 2004 00:12:28 -0500, Myrna Larson
wrote:

I expect the underlying problem is that in your source range, the
number format varies from one cell to another. In that situation, the
.Numberformat property returns NULL. It doesn't return an array of
formats for each cell in the range.

To demonstrate: put some data in, say A1:A3, and set different number
formats for at least one of the cells. Then select those cells, in the
VBE immediate window type ? Selection.Numberformat. You'll see that
it prints NULL.

If the formats vary, and you want to replicate them, you'll have to do
it a cell at a time, or at least do it in "chunks" of cells, all of
which have the same number format.


On Mon, 11 Oct 2004 23:54:45 -0500, SteveS
wrote:


I must be missing something obvious here... I am trying to use a
range copy to copy values and formats from a series of worksheets.
The values come over fine, but the number formats do not.

What is the trick to copy number formats? The vba is:
With sh.Range(sh.Cells(FirstRow, FirstCol), sh.Cells(shLast,
LastCol)) DestSh.Cells(Last + 1, 1).Resize(.Rows.Count, _
Columns.Count).Value = .Value
DestSh.Cells(Last + 1, 1).Resize(.Rows.Count, _
Columns.Count).NumberFormat = .NumberFormat
End With

Thanks,
Steve




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Copy Number Formats

assigning NULL or a mixed bag of numberformats throws exception in all
versions on my PC (as expected)


Like Myrna, assigning a number format of NULL does not error for me.

Selection.NumberFormat = Null

With identical formats this does nothing, ie original format retained. With
mixed number formats all are changed to General. But no error.

Regards,
Peter


"keepITcool" wrote in message
...
To OP:
If you're coding for xl2000+ then you could use:

rngSrc.Copy
rngDst.PasteSpecial xlPasteValuesAndNumberFormats

To Myrna:
assigning NULL or a mixed bag of numberformats throws exception in all
versions on my PC (as expected)

i did note that assigning EMPTY clear formats... (not surprisingly)




keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


Myrna Larson wrote:

PS: The interesting thing is that assigning a number format of NULL,
as your code is probably doing, doesn't cause a run-time error.

On Tue, 12 Oct 2004 00:12:28 -0500, Myrna Larson
wrote:

I expect the underlying problem is that in your source range, the
number format varies from one cell to another. In that situation, the
.Numberformat property returns NULL. It doesn't return an array of
formats for each cell in the range.

To demonstrate: put some data in, say A1:A3, and set different number
formats for at least one of the cells. Then select those cells, in the
VBE immediate window type ? Selection.Numberformat. You'll see that
it prints NULL.

If the formats vary, and you want to replicate them, you'll have to do
it a cell at a time, or at least do it in "chunks" of cells, all of
which have the same number format.


On Mon, 11 Oct 2004 23:54:45 -0500, SteveS
wrote:


I must be missing something obvious here... I am trying to use a
range copy to copy values and formats from a series of worksheets.
The values come over fine, but the number formats do not.

What is the trick to copy number formats? The vba is:
With sh.Range(sh.Cells(FirstRow, FirstCol), sh.Cells(shLast,
LastCol)) DestSh.Cells(Last + 1, 1).Resize(.Rows.Count, _
Columns.Count).Value = .Value
DestSh.Cells(Last + 1, 1).Resize(.Rows.Count, _
Columns.Count).NumberFormat = .NumberFormat
End With

Thanks,
Steve








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Copy Number Formats

correction:
xlXP and xl2003 throw error.
xl97 accepts

selection.numberformat = Null


keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Peter T" <peter_t@discussions wrote:

assigning NULL or a mixed bag of numberformats throws exception in
all versions on my PC (as expected)


Like Myrna, assigning a number format of NULL does not error for me.

Selection.NumberFormat = Null

With identical formats this does nothing, ie original format retained.
With mixed number formats all are changed to General. But no error.

Regards,
Peter


"keepITcool" wrote in message
...
To OP:
If you're coding for xl2000+ then you could use:

rngSrc.Copy
rngDst.PasteSpecial xlPasteValuesAndNumberFormats

To Myrna:
assigning NULL or a mixed bag of numberformats throws exception in
all versions on my PC (as expected)

i did note that assigning EMPTY clear formats... (not surprisingly)




keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


Myrna Larson wrote:

PS: The interesting thing is that assigning a number format of
NULL, as your code is probably doing, doesn't cause a run-time
error.

On Tue, 12 Oct 2004 00:12:28 -0500, Myrna Larson
wrote:

I expect the underlying problem is that in your source range, the
number format varies from one cell to another. In that situation,
the .Numberformat property returns NULL. It doesn't return an array
of formats for each cell in the range.

To demonstrate: put some data in, say A1:A3, and set different
number formats for at least one of the cells. Then select those
cells, in the VBE immediate window type ? Selection.Numberformat.
You'll see that it prints NULL.

If the formats vary, and you want to replicate them, you'll have to
do it a cell at a time, or at least do it in "chunks" of cells, all
of which have the same number format.


On Mon, 11 Oct 2004 23:54:45 -0500, SteveS
wrote:


I must be missing something obvious here... I am trying to use a
range copy to copy values and formats from a series of worksheets.
The values come over fine, but the number formats do not.

What is the trick to copy number formats? The vba is:
With sh.Range(sh.Cells(FirstRow, FirstCol), sh.Cells(shLast,
LastCol)) DestSh.Cells(Last + 1, 1).Resize(.Rows.Count, _
Columns.Count).Value = .Value
DestSh.Cells(Last + 1, 1).Resize(.Rows.Count, _
Columns.Count).NumberFormat = .NumberFormat
End With

Thanks,
Steve







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
Copy all formats and objects Learning VBA Excel Discussion (Misc queries) 5 January 23rd 10 11:25 PM
Copy column, paste special formulas & number formats doesn't work Beckey Excel Discussion (Misc queries) 3 July 30th 09 07:51 PM
Copy worksheets and formats Ken Excel Discussion (Misc queries) 1 January 31st 05 12:00 AM
Copy Conditional Formats MM[_4_] Excel Programming 2 August 3rd 04 02:34 PM
using array to copy formats as well... Gbiwan Excel Programming 3 February 19th 04 07:34 PM


All times are GMT +1. The time now is 07:13 AM.

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

About Us

"It's about Microsoft Excel"