Replace pattern of characters

F

Fernando

I need replace the contents of a column as follows

The column will have have empty rows rows with 4 characters and rows with
8 characters.

For the rows with 8 characters I need to insert a "/' in between.

e.g.

XXXXWWWW -> XXXX/WWWW.

I know I can use ???????? in the search, but how do I get the replace to
only insert the "/" in between the characters?

The first four characters are not always the same.

Thank you for your help

JFercan.
 
R

Ron Rosenfeld

I need replace the contents of a column as follows

The column will have have empty rows rows with 4 characters and rows with
8 characters.

For the rows with 8 characters I need to insert a "/' in between.

e.g.

XXXXWWWW -> XXXX/WWWW.

I know I can use ???????? in the search, but how do I get the replace to
only insert the "/" in between the characters?

The first four characters are not always the same.

Thank you for your help

JFercan.

You could use a formula:

=IF(LEN(A1)=8,LEFT(A1,4)&"/"&RIGHT(A1,4),A1)

Otherwise, you would probably have to use a VBA macro to change the cell
contents "in place".
--ron
 
D

David Biddulph

If you're saying you need to put the slant between the 4th & 5th characters
in the 8 character entries, & leave the other rows unaltered, you could try:
=IF(A1="","",IF(LEN(A1)=8,LEFT(A1,4)&"/"&RIGHT(A1,4),A1))
 
R

Ron Rosenfeld

You could use a formula:

=IF(LEN(A1)=8,LEFT(A1,4)&"/"&RIGHT(A1,4),A1)

Otherwise, you would probably have to use a VBA macro to change the cell
contents "in place".
--ron


That should be:
=IF(A1="","",IF(LEN(A1)=8,LEFT(A1,4)&"/"&RIGHT(A1,4),A1))

--ron
 
F

Fernando

Thank you for your help.

I was hoping for an easier way, but I guess a macro won't be that bad.

Thanks for your replies.
 
R

Ron Rosenfeld

Thank you for your help.

I was hoping for an easier way, but I guess a macro won't be that bad.

Thanks for your replies.


Option Explicit

Sub Slash()
Dim c As Range

For Each c In Selection
If Len(c.Text) = 8 Then
c.Value = Left(c.Text, 4) & "/" & Right(c.Text, 4)
End If
Next c
End Sub

--ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top