Solved

Extract titles from string using VBA

Posted on 2013-11-07
3
335 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 52

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

624 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