Solved

Extract titles from string using VBA

Posted on 2013-11-07
3
294 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 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now