Solved

Extract titles from string using VBA

Posted on 2013-11-07
3
328 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 51

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

751 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