Searching and appending "The "

rmanke

New Member
Joined
Jun 27, 2011
Messages
4
Hello,

This is my first post to the forum, so please be kind... ;)

I tried searching everywhere, but the terminology is so common that I cannot find a solution to my problem.

I would like to determine a search and append function that will search for the word "The " at the beginning of a cell, and if it exists, trim it, and append it to the end of the cell in a single column or in multiple columns.

Two examples:

BEFORE:
"The Beatles"
"The Beginning and the End"

AFTER:
"Beatles, The"
"Beginning and the End, The"


Can anyone point me to a good example, or help me out? It would be much appreciated!

Thanks in advance!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try this:
=IF(EXACT(TRIM(LEFT(A1,FIND(" ",A1))),"The"),TRIM(LEFT(A1,FIND(" ",A1)))&", "&RIGHT(A1,LEN(A1)-4),"")
 
Last edited:
Upvote 0
small mistake, forgot to put ,

text has to at cell a1

=TRIM(MID(A1,SEARCH("The",A1)+3,LEN(A1)))&", The"
 
Upvote 0
Hi and Welcome to the Board.
Assuming ALL cells have "The" at the start
In an adjacent column try
Code:
=IF(LEFT(A1,4)="The ",REPLACE(A1,1,4,),"")&", "&"The "
 
Last edited:
Upvote 0
One more for you to consider...

=IF(LEFT(A1,4)="The ",MID(A1,5,999)&", The",A1)
 
Upvote 0
Awesome, thanks folks!

No, not all fields have "The " at the beginning, so I need to recursively check the fields.

I'm helping a friend with his karaoke show list, which has over 40,000 rows in a spreadsheet, so this will save a lot of time.

Thanks!
 
Upvote 0
Code:
[COLOR="Blue"]Function[/COLOR] AttachThe(Str [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]String[/COLOR]) [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]String[/COLOR]
    Application.Volatile
    [COLOR="Blue"]Dim[/COLOR] s [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]String[/COLOR]
    [COLOR="Blue"]With[/COLOR] CreateObject("VBScript.RegExp")
        .Pattern = "^""\s*The"
        s = Trim$(.Replace(Str, ""))
        AttachThe = """" & Left(s, Len(s) - 1) & ", The"""
    [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]With[/COLOR]
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Function[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,762
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top