Solved

Excel 2007 VB Code To Remove Text String

Posted on 2015-01-28
3
136 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 32

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

823 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