?
Solved

Excel 2007 VB Code To Remove Text String

Posted on 2015-01-28
3
Medium Priority
?
153 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 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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 article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

752 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