Try the following User Defined Function (UDF)
Public Function Equals(inpt As String) As String Equals = "" ary = Split(Application.WorksheetFunction.Trim(inpt), " ") For Each a In ary If InStr(1, a, "=") > 0 Then Equals = a Exit Function End If Next a End Function
User Defined Functions (UDFs) are very easy to install and use:
- ALT-F11 brings up the VBE window
- ALT-I ALT-M opens a fresh module
- paste the stuff in and close the VBE window
If you save the workbook, the UDF will be saved with it. If you are using a version of Excel later then 2003, you must save the file as .xlsm rather than .xlsx
To remove the UDF:
- bring up the VBE window as above
- clear the code out
- close the VBE window
To use the UDF from Excel:
=equals(A1)
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
and for specifics on UDFs, see:
http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx
Macros must be enabled for this to work!
EDIT#1:
You can do this without VBA, using the same methodology. With data in A1, in C1 enter:
=TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",999)),COLUMNS($A:A)*999-998,999))
and copy across. Then in B1 enter:
=INDEX(C1:IV1,MATCH("*=*",C1:IV1,0))