Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Characters in a cell

I need a macro that will look at a cell and if it only has one character then add zero's in front of it until it has 3 characters.

Example: if cell "A1" = "10" then the macro would make it say "010"
if cell "A1" = "BA" then the macro would make it say "0BA"

Is there a setting that looks at the number of characters???

Thanks,
Kevin

  #2   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Characters in a cell

len("string")
works either in a worksheet or a VBA function


-----Original Message-----
I need a macro that will look at a cell and if it only

has one character then add zero's in front of it until it
has 3 characters.

Example: if cell "A1" = "10" then the macro would make

it say "010"
if cell "A1" = "BA" then the macro would

make it say "0BA"

Is there a setting that looks at the number of

characters???

Thanks,
Kevin

.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Characters in a cell

len(Range("A1")) will tell you how many characters.

if you cell contains a number, then you will either have to store it as a
text string to see a leading zero or produce the leading zero by using a
number format like "000"

--
Regards,
Tom Ogilvy

"KevGrn114" wrote in message
...
I need a macro that will look at a cell and if it only has one character

then add zero's in front of it until it has 3 characters.

Example: if cell "A1" = "10" then the macro would make it say "010"
if cell "A1" = "BA" then the macro would make it say "0BA"

Is there a setting that looks at the number of characters???

Thanks,
Kevin



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Characters in a cell

So would that be.

if activecell < len("3") the
then something

or just active cell=len("3") ?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Characters in a cell

if len(activeCell) = 3 then

--
Regards,
Tom Ogilvy

"KevGrn114" wrote in message
...
So would that be..

if activecell < len("3") then
then something?

or just active cell=len("3") ??





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Characters in a cell

So can I just say len(activecell) =3 and forget it? as long as the cell attribute is set to text?
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Characters in a cell

if the cell contains text or numbers, you can use len.

Range("A1").Value =10
? len(range("A1").Value)
2

You can use

len(range("A1').Text) to check the number of characters being displayed
regardless of what is in the cell.

? range("A1").Text
#N/A
? len(Range("A1").text)
4

If the cell will never hold more than 3 characters you could just do

Dim sVal as String
sVal = "'" & Right("000" & ActiveCell.Text,3)
ActiveCell.Text = sVal

--
Regards,
Tom Ogilvy



"KevGrn114" wrote in message
...
So can I just say len(activecell) =3 and forget it? as long as the cell

attribute is set to text?


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Characters in a cell

Thanks Tom, this helps out alot. Its working for me now..
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 5 characters in a cell to 6 characters by adding a zero Helenf Excel Discussion (Misc queries) 4 May 18th 09 04:43 PM
Need to use only 14 characters in cell Susie Excel Discussion (Misc queries) 2 February 7th 08 12:10 AM
Transfer specific characters from cell to another cell. Willing to learn New Users to Excel 3 June 17th 07 02:14 AM
Need more characters in a cell Kelly New Users to Excel 1 December 2nd 06 02:04 AM
cell max characters npereira Excel Discussion (Misc queries) 5 October 19th 05 02:25 PM


All times are GMT +1. The time now is 09:10 AM.

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"