Solved

Extract titles from string using VBA

Posted on 2013-11-07
3
318 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 50

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Excel Multi Sheet Formula 13 32
List Box Entries Excel 2010 5 29
Expanding and filling year gaps in multiple listings 6 25
simple excel formula 4 13
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

856 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