?
Solved

Excel 2007 VB Code To Remove Text String

Posted on 2015-01-28
3
Medium Priority
?
169 Views
Last Modified: 2015-01-29
Hello,

Hoping someone can assist in developing a VB code that will do the following:

Column A contains a number of rows of text.  The text begins with an employees name (semi-colon;) employee ID (semi-colon;).  For example:   John Doe; 12345;

I'd like the code to look at each row in Column A that contains text and remove the employees name, semi-colon, employee ID, semi-colon.  Basically if the code could somehow identify the second semi-colon and remove all text to before and including that point it would be ideal.

Any assistance would be appreciated.  Thanks!
0
Comment
Question by:Escanaba
3 Comments
 
LVL 48

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 40576014
This should do it...

Range("A:A").Replace "*;*;", ""

Open in new window


Wayne
0
 
LVL 39

Accepted Solution

by:
nutsch earned 2000 total points
ID: 40576405
Wayne, this will work, but only if you have a single occurrence of *;*; in the cell.
If there are additional columns, separated by semi-columns, some could/will get dropped. The following code (to be tweaked depending on your need) will address that.

Dim rg As Range

For Each rg In range("A1:A" & cells(rows.count,"A").end(xlup)).cells
rg= Mid(rg, InStr(rg, ";") + 1 + InStr(Mid(rg, 1 + InStr(rg, ";")), ";"))
Next rg

Open in new window


Thomas
0
 
LVL 34

Expert Comment

by:Rob Henson
ID: 40577249
Assuming value in A2, the following formula will also do the necessary:

=TRIM(RIGHT(SUBSTITUTE(A2,";","",1),LEN(SUBSTITUTE(A2,";","",1))-FIND(";",SUBSTITUTE(A2,";","",1),1)))

Copied down for the extent of data in column A and then Copy & Paste values back into column A to overwrite original.

This finds and removes the first occurence of a Semicolon, leaving the second occurence for the FIND to find to get its position and then RIGHT returns everything after it, with the TRIM removing any surplus spaces.

Thanks
Rob H
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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

862 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