Extract data from text string

Nubie2019

New Member
Joined
Mar 6, 2019
Messages
9
"Mon, Mar. 11, 2018ABC, FGHO117 Comments"

I want to extract from the above text string, "Mon, Mar. 11, 2018" in one cell, and "ABC, FGH" in another cell.

Is it possible without using VBA?

Thanks
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi,

It would be useful to see a few more examples so that we can be sure that a given formula will work for all cases.

Regards
 
Upvote 0
Assuming the text string is in cell A1
1. Enter formula in B1
=LEFT(A1,18)

2.Enter in C1
=LEFT(SUBSTITUTE(A1,B1,""),8)
 
Upvote 0
Hi, few more examples,

"Thu, Feb 16GGHL, FGJK, LIM2 Comments"

"Feb 2, 2018FGH, IJK, LK9 comments"

In every case, I need the date section extracted and the upper case symbols in the middle. I need the date and the symbols in two seperate cells.

Thanks
 
Upvote 0
Hi Alley, the text string will not always be the same length, I have provided a few more examples below in response to XOR LX's request.
 
Upvote 0
Hi Alley, the text string will not always be the same length, I have provided a few more examples below in response to XOR LX's request.
It is worse than that... not only are they different lengths, but their construction is different... years or no years, day of week or no day of week, period after the month or no period after the month, etc.



Hi, few more examples,

"Thu, Feb 16GGHL, FGJK, LIM2 Comments"

"Feb 2, 2018FGH, IJK, LK9 comments"

In every case, I need the date section extracted and the upper case symbols in the middle. I need the date and the symbols in two seperate cells.
These should have been in your first message as your original example was not representative of what you have now posted.

See if these UDF's (user defined functions) do what you want...
Code:
Function GetDate(S As String) As String
  Dim X As Long
  For X = 1 To Len(S) - 1
    If Mid(S, X, 2) Like "#[A-Z]" Then
      GetDate = Left(S, X)
      Exit For
    End If
  Next
End Function

Function GetLetters(S As String) As String
  Dim X As Long
  For X = 1 To Len(S) - 1
    If Mid(S, X, 2) Like "[A-Z][A-Z]" Then
      GetLetters = Mid(S, X)
      Exit For
    End If
  Next
  For X = 1 To Len(GetLetters) - 1
    If Mid(GetLetters, X, 2) Like "[A-Z][!A-Z ,]" Then
      GetLetters = Left(GetLetters, X)
      Exit For
    End If
  Next
End Function

HOW TO INSTALL UDFs
------------------------------------
If you are new to UDFs, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. You can now use GetDate and GetLetters just like they was a built-in Excel functions. For example,

=GetDate(A1)

=GetLetters(A1)

If you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,448
Members
448,966
Latest member
DannyC96

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