Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Replacing characters with leading zeroes

I am attempting to replace the character "O" with a
leading zero in a column. The column currently looks
something like this:

OOO55
OOO3
OOOOO567
OO1

I would like it to look like:

00055
0003
00000567
001

I have tried formatting the column as text and then doing
a find and replace. However, as soon as the replace
finishes the column format switches back to a number
format and strips the zeroes. Unfortunately, I can't use
a custom number format because there is no consistency to
the length of the numbers.

Any ideas?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Replacing characters with leading zeroes

On Tue, 27 Jul 2004 17:51:50 -0700, "Demian Valle"
wrote:

I am attempting to replace the character "O" with a
leading zero in a column. The column currently looks
something like this:

OOO55
OOO3
OOOOO567
OO1

I would like it to look like:

00055
0003
00000567
001

I have tried formatting the column as text and then doing
a find and replace. However, as soon as the replace
finishes the column format switches back to a number
format and strips the zeroes. Unfortunately, I can't use
a custom number format because there is no consistency to
the length of the numbers.

Any ideas?



=TEXT(SUBSTITUTE(A1,"O",""),REPT("0",LEN(A1)))


--ron
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Replacing characters with leading zeroes

On Tue, 27 Jul 2004 17:51:50 -0700, "Demian Valle"
wrote:

I am attempting to replace the character "O" with a
leading zero in a column. The column currently looks
something like this:

OOO55
OOO3
OOOOO567
OO1

I would like it to look like:

00055
0003
00000567
001

I have tried formatting the column as text and then doing
a find and replace. However, as soon as the replace
finishes the column format switches back to a number
format and strips the zeroes. Unfortunately, I can't use
a custom number format because there is no consistency to
the length of the numbers.

Any ideas?


Another thought. If you want to change the values in place, and have them come
out as a formatted number, you could use this UDF:

===================================
Sub foo()
Dim c As Range
Dim NumZeros As Integer

For Each c In Selection
NumZeros = Len(Trim(c.Text))
c.Value = Replace(c.Text, "O", "")
c.NumberFormat = Application.WorksheetFunction.Rept("0", NumZeros)
Next c

End Sub
=================================

--ron
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Replacing characters with leading zeroes

Thanks Ron. This is exactly what I needed.

Demian


-----Original Message-----
On Tue, 27 Jul 2004 17:51:50 -0700, "Demian Valle"


wrote:

I am attempting to replace the character "O" with a
leading zero in a column. The column currently looks
something like this:

OOO55
OOO3
OOOOO567
OO1

I would like it to look like:

00055
0003
00000567
001

I have tried formatting the column as text and then

doing
a find and replace. However, as soon as the replace
finishes the column format switches back to a number
format and strips the zeroes. Unfortunately, I can't

use
a custom number format because there is no consistency

to
the length of the numbers.

Any ideas?


Another thought. If you want to change the values in

place, and have them come
out as a formatted number, you could use this UDF:

===================================
Sub foo()
Dim c As Range
Dim NumZeros As Integer

For Each c In Selection
NumZeros = Len(Trim(c.Text))
c.Value = Replace(c.Text, "O", "")
c.NumberFormat = Application.WorksheetFunction.Rept

("0", NumZeros)
Next c

End Sub
=================================

--ron
.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Replacing characters with leading zeroes

On Wed, 28 Jul 2004 08:53:27 -0700, "Demian Valle"
wrote:

Thanks Ron. This is exactly what I needed.

Demian


You're welcome. Glad to help.


--ron
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
Sorry, leading zeroes again :-(( Argghhhh Excel Discussion (Misc queries) 7 November 13th 06 10:26 PM
Leading Zeroes Melissa Excel Discussion (Misc queries) 3 October 11th 06 07:38 PM
Leading Zeroes Ken Excel Discussion (Misc queries) 1 October 7th 05 03:17 PM
No decimals and leading zeroes gcotterl Excel Discussion (Misc queries) 2 April 18th 05 06:50 AM
CSV leading zeroes Tim_nol Excel Discussion (Misc queries) 2 December 28th 04 08:19 PM


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