0

I have a cell in Excel that contains the following:

@dickfundy @ThatKevinSmith @aliciamalone @MovieMantz @dickfundy nope just Stranger Things Season 2 or Ready Player https:xxxxxxxxxxx

I want to remove the usernames (everything starting with a "@") and I also want to remove the web-link (the "https:xxxxxxxxxxx"), and I want to end up with this in the cell:

nope just Stranger Things Season 2 or Ready Player

I have 60,000 other cells that contain similar text. How do I do this?

rsmalley74
  • 33
  • 4

3 Answers3

2

I believe your version of Excel has the TEXTJOIN function. That being the case you can use this array-formula

=TEXTJOIN(" ",TRUE,IF((LEFT(TRIM(MID(SUBSTITUTE(TRIM(A1)," ",REPT(" ",999)),seq_999,999)))="@")+(LEFT(TRIM(MID(SUBSTITUTE(TRIM(A1)," ",REPT(" ",999)),seq_999,999)),4)="http"),"",TRIM(MID(SUBSTITUTE(TRIM(A1)," ",REPT(" ",999)),seq_999,999))))

where seq_999 is a named formula that

refers to:  =IF(ROW(INDEX(Sheet1!$1:$65535,1,1):INDEX(Sheet1!$1:$65535,255,1))=1,1,(ROW(INDEX(Sheet1!$1:$65535,1,1):INDEX(Sheet1!$1:$65535,255,1))-1)*999)

To enter/confirm an array formula, hold down ctrl + shift while hitting enter. If you do this correctly, Excel will place braces {...} around the formula seen in the formula bar.

Ron Rosenfeld
  • 53,870
  • 7
  • 28
  • 60
1

If you deleted up to the last user name (with Replace *@ with nothing) then you might apply:

=LEFT(MID(A1,FIND(" ",A1),LEN(A1)),FIND("http",MID(A1,FIND(" ",A1)+1,LEN(A1))))

SO53291434 example

pnuts
  • 58,317
  • 11
  • 87
  • 139
  • Thank you. It seems to work however it omits the first word that is leftover. So in the above example the word "nope" is omitted. Also, for other cells where only one word is leftover after applying this formula, the cell is then left blank. – rsmalley74 Nov 14 '18 at 01:15
1

As a UDF:

Function FixIt(s As String) As String
    s = CleanUp(s, "@")
    s = CleanUp(s, "http")
    FixIt = Trim(s)
End Function

'remove all text segments beginning with LookFor, up to the next space
'  or until the end of the input string s
Function CleanUp(s As String, LookFor As String) As String
    Dim pos As Long, pos2 As Long, rv As String
    rv = s
    pos = InStr(1, rv, LookFor)
    Do While pos > 0
        pos2 = InStr(pos + 1, rv, " ")
        If pos2 = 0 Then pos2 = Len(rv)
        rv = Left(rv, pos - 1) & Right(rv, Len(rv) - pos2)
        pos = InStr(1, rv, LookFor)
    Loop
    CleanUp = rv
End Function

If you want something robust:

How to use Regular Expressions (Regex) in Microsoft Excel both in-cell and loops

Tim Williams
  • 154,628
  • 8
  • 97
  • 125