Solved

Excel 2007 VB Code To Remove Text String

Posted on 2015-01-28
3
135 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 47

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 500 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 31

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

747 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

10 Experts available now in Live!

Get 1:1 Help Now