Solved

Extract titles from string using VBA

Posted on 2013-11-07
3
312 Views
Last Modified: 2013-11-08
Dear Experts:

I got a huge data list with column headers where the (German) titles need to be extracted from a string in Column G:

Now the strings in Column G say for example:

Prof. Dr. Dr. med. John Doe
Prof. Dr. Elvis Costello
Prof. Jane Forseth
Dr. Miriam Sensing

I would like to run a macro that searches for the following strings (only! whole terms, no parts of the strings) ...
... Prof. Dr. Dr. med.
... Prof. Dr.
... Prof.
... Dr.
and extracts the found strings and inserts them in column H in the respective row.

The original string in Column G is to remain the same.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
0
Comment
Question by:AndreasHermle
  • 2
3 Comments
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39629846
Hi

pls try

Public Function fExtractTitles(strFullname As String) As String
Set WsF = Application.WorksheetFunction
fExtractTitles = ""
arrTitles = Split("Prof.,Dr.,med.", ",")
arrString = Split(strFullname, " ")
For idx = 0 To UBound(arrString)
bFound = False
    For Each ttl In arrTitles
        If arrString(idx) = ttl Then
            idxResult = idx + 1
            bFound = True
            Result = Left(strFullname, WsF.Search(Chr(127), WsF.Substitute(strFullname, " ", Chr(127), idxResult)) - 1)
        End If
    Next
If bFound = False Then Exit For
Next
fExtractTitles = Result

End Function

Open in new window

Regards
0
 

Author Comment

by:AndreasHermle
ID: 39629854
Hi Rgonzo,

thank you very much for your swift and professional help. Looks very,very sophisticated to me.

Okay, I'll give it a try and let you know.

Regards, Andreas
0
 

Author Closing Comment

by:AndreasHermle
ID: 39634861
Dear Rgonzo,

I am truly impressed! :)  this works just great!

This is real coding professionalism. Thank you very much for your great support.

Regards, Andreas
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvieā€¦
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question