It appears that your data consists of a set of items that:
- are separated by comma space
- may have an email as the last item
If this is always the case, then consider the following User Defined Function:
Public Function noemail(s As String) As String
Dim i As Long, L As Long
If InStr(s, "@") = 0 Then
noemail = s
Exit Function
End If
L = Len(s)
For i = L To 1 Step -1
If Mid(s, i, 1) = "," Then
noemail = Left(s, i - 1)
Exit Function
End If
Next i
End Function
It checks the string for @. If the @ is present, it looks for the preceding comma and clips the string at the point:
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:
=noemail(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!