Solved

Excel 2007 VB Code To Remove Text String

Posted on 2015-01-28
3
139 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 33

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 Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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…

726 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