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

Is it possible to format numbers into text from vba code? The situation is
that we insert data from a database into an Excel spreadsheet. One of the
columns is an address column. The address column often has normal address
data, but sometimes it will only contain a number like 1435, which causes
Excel to treat that cells data as a number. So when we import the data back
from Excel the column is misread because of the different formats for the
cells. The database export unfortunately wipes out the column type, so
changing its format type to text does nothing. Can the format command in VBA
change a cells type?

Thanks for the help,
ACFalcon
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Format Number to Text

Hi,

Columns(1).numberformat="@" will format Col A to text and then numbers are
treated as text.

HTH

"ACFalcon" wrote:

Is it possible to format numbers into text from vba code? The situation is
that we insert data from a database into an Excel spreadsheet. One of the
columns is an address column. The address column often has normal address
data, but sometimes it will only contain a number like 1435, which causes
Excel to treat that cells data as a number. So when we import the data back
from Excel the column is misread because of the different formats for the
cells. The database export unfortunately wipes out the column type, so
changing its format type to text does nothing. Can the format command in VBA
change a cells type?

Thanks for the help,
ACFalcon

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Format Number to Text

But when that str(1234) hits A1 (and A1 is formatted as General), then A1 will
still be a number.

You could force it to be text:

Range("A1") = "'1234"
(included the leading apostrophe)

or you could format the cell as Text first.

with range("a1")
.numberformat = "@"
.value = 1234
end with



Leith Ross wrote:

Hello ACFalcon.

You can convert a number in VBA to a string by using the STR function.

EXAMPLE:
Range("A1") = Str(1234)

The value in A1 is now text and not a number. As for the Format
statement changing a cell's type, the answer is no. All cells are
Variant data types.

Sincerely,
Leith Ross

--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=493932


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Format Number to Text


Hello ACFalcon.

You can convert a number in VBA to a string by using the STR function.

EXAMPLE
Range("A1") = Str(1234)

The value in A1 is now text and not a number. As for the Forma
statement changing a cell's type, the answer is no. All cells ar
Variant data types.

Sincerely,
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=49393

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
Convert numbers from text format to number format merlin68 Excel Discussion (Misc queries) 7 June 20th 07 07:03 PM
Change number (in text format) to numeric format Pam Excel Discussion (Misc queries) 5 October 24th 05 07:45 PM
How to change text format .126 to number format 0.126 ? vitality Excel Worksheet Functions 2 October 6th 05 01:02 PM
convert text-format number to number in excel 2000%3f Larry Excel Discussion (Misc queries) 1 July 29th 05 08:18 PM
How do i change numbers in text format to number format? Greg New Users to Excel 1 December 14th 04 05:22 PM


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