Copying numeric text with leading zeros

A

Al

XL2003 on XP

I’m using a Ron de Bruin macro to merge all data from workbooks in a
folder(1), but it converts numeric text with leading zeros into numbers when
it copies the data. The relevant portion of code is:

Set destRange = BaseWks.Range("A" & rnum)

'we copy the values from the sourceRange to the destRange
With sourceRange
Set destRange = destRange.Resize(.Rows.Count, .Columns.Count)
End With
destRange.Value = sourceRange.Value

Can I prevent that from happening, or do I need another macro to add the
zeros back?
 
M

Michael

You may have to format your destination cell also:
With SourceRange
.NumberFormat = "@"
End With
destRange.Value = SourceRange.Text

--
If this posting was helpful, please click on the Yes button.
Regards,

Michael Arch.
 
A

Al

Using

destRange.Value = SourceRange.Text

doesn't work in my case since my source workbooks columns with regular text
and numbers as well as numeric text.
Preformatting the appropriate columns of the destination workbook as you
suggest and using my original

destRange.Value = sourceRange.Value

statement does the trick.

Thanks, Michael.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top