Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default vba is converting text to values!

Need help with vba in Excel. I have a list of zip codes many of which begin
with zeroes so I have converted them to text using Excel's built-in Text
function: Text(ZipCode,"00000"). When I run the vba command to assign the
value of a zip to another cell on the spreadsheet, it converts it to a
number, not as text, and thus my routine bombs on subsequent lines of code on
a "type mismatch."

ex: Range("NewZip").Value = Range("OldZip").Value

where OldZip is the original zip code formatted as text and NewZip is the
cell where the value of the zip code is assigned--with the leading zeroes
stripped off. Is there some sort of Text command in vba whereby I could do
something like:

Range("NewZip").Value = Text(Range("OldZip).Value,"0000")

you know, kind of like the built-in Excel text command?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default vba is converting text to values!

Very close.

Range("NewZip").Value = Format(Range("OldZip).Value,"00000")

(I think you were missing a zero in your format.)

--

Vasant

"Bill_S" wrote in message
...
Need help with vba in Excel. I have a list of zip codes many of which

begin
with zeroes so I have converted them to text using Excel's built-in Text
function: Text(ZipCode,"00000"). When I run the vba command to assign the
value of a zip to another cell on the spreadsheet, it converts it to a
number, not as text, and thus my routine bombs on subsequent lines of code

on
a "type mismatch."

ex: Range("NewZip").Value = Range("OldZip").Value

where OldZip is the original zip code formatted as text and NewZip is the
cell where the value of the zip code is assigned--with the leading zeroes
stripped off. Is there some sort of Text command in vba whereby I could

do
something like:

Range("NewZip").Value = Text(Range("OldZip).Value,"0000")

you know, kind of like the built-in Excel text command?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default vba is converting text to values!

Range("NewZip").NumberFormat = "@" 'Set to TEXT format 1st
Range("NewZip").Value = Range("OldZip").Value

"Bill_S" wrote in message ...
Need help with vba in Excel. I have a list of zip codes many of which begin
with zeroes so I have converted them to text using Excel's built-in Text
function: Text(ZipCode,"00000"). When I run the vba command to assign the
value of a zip to another cell on the spreadsheet, it converts it to a
number, not as text, and thus my routine bombs on subsequent lines of code on
a "type mismatch."

ex: Range("NewZip").Value = Range("OldZip").Value

where OldZip is the original zip code formatted as text and NewZip is the
cell where the value of the zip code is assigned--with the leading zeroes
stripped off. Is there some sort of Text command in vba whereby I could do
something like:

Range("NewZip").Value = Text(Range("OldZip).Value,"0000")

you know, kind of like the built-in Excel text command?



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
Converting text to numerical values J New Users to Excel 1 February 16th 10 04:14 PM
Converting Text into Values Terry Bennett Excel Worksheet Functions 6 August 27th 09 02:03 AM
Converting values to text Keith Rathband New Users to Excel 3 October 4th 08 11:18 PM
Converting Numeric values to Text shail Excel Worksheet Functions 2 September 5th 06 04:50 PM
Converting Text Values to Dates Frank Winston Excel Discussion (Misc queries) 12 June 5th 06 11:35 AM


All times are GMT +1. The time now is 04:02 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"