PC Review


Reply
Thread Tools Rate Thread

Copying numeric text with leading zeros

 
 
Al
Guest
Posts: n/a
 
      18th Dec 2008
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?

--
Al C
 
Reply With Quote
 
 
 
 
Michael
Guest
Posts: n/a
 
      18th Dec 2008
Try:
destRange.Value = sourceRange.Text

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

Michael Arch.




"Al" wrote:

> 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?
>
> --
> Al C

 
Reply With Quote
 
Michael
Guest
Posts: n/a
 
      18th Dec 2008
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.




"Michael" wrote:

> Try:
> destRange.Value = sourceRange.Text
>
> --
> If this posting was helpful, please click on the Yes button.
> Regards,
>
> Michael Arch.
>
>
>
>
> "Al" wrote:
>
> > 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?
> >
> > --
> > Al C

 
Reply With Quote
 
Al
Guest
Posts: n/a
 
      18th Dec 2008
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.
--
Al C


"Michael" wrote:


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ignore Leading Zeros in Mixed Alpha-Numeric Text Fields Select Query excelCPA Microsoft Access Queries 5 14th Oct 2009 08:54 PM
Re: CSV and Numeric Strings with Leading Zeros Beege Microsoft Excel Worksheet Functions 1 21st Feb 2008 09:33 PM
Need quick help! Convert Numeric to Text and keep leading zeros Gilbert Noetzel Microsoft Access External Data 4 1st May 2007 08:55 PM
Display leading zeros in numeric value without converting to text =?Utf-8?B?R21vbm55?= Microsoft Excel Misc 4 5th Oct 2006 09:05 PM
removeing leading zeros in a text string (not a numeric field) Brian Henry Microsoft VB .NET 4 4th May 2004 09:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:25 AM.