Solved

Parse everything after the comma

Posted on 2014-04-19
7
196 Views
Last Modified: 2014-04-22
I have values in a column that I need to parse out the values that are after each comma in the string.  Leaving the original column intact.
1234-1234,AO-16,AO-19,HJ-39,TH-20
1234-1234,AO-16,AO-19,HJ-39
1234-1234,AO-16,AO-19
1234-1234,AO-16

In the result location, which I would like in the column just to its right have the hyphen replaced with an underscore.
It does not matter if it is in a formula, or vba, but perfer a vba solution. Thanks.

Resulting columns would look something like:
1234-1234,AO-16,AO-19,HJ-39,TH-20     AO_16     AO_19     HJ_39     TH_20
1234-1234,AO-16,AO-19,HJ-39               AO_16     AO_19     HJ_39
1234-1234,AO-16,AO-19                        AO_16     AO_19
1234-1234,AO-16                                   AO_16
0
Comment
Question by:RWayneH
  • 3
  • 3
7 Comments
 
LVL 34

Assisted Solution

by:Dan Craciun
Dan Craciun earned 250 total points
ID: 40010273
See the attached file, using Patrick Matthews's RegExpFind function.

HTH,
Dan
test.xlsm
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 40010321
Why not simply make a copy of the first column in the second column and then perform a text-to-column on the new column?
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 40010329
Here is a macro to do this

Sub Macro1()
    Range("A:A").Copy Range("B:B")
    Range("B:B").TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
        :=Array(Array(1, 9), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1)), _
        TrailingMinusNumbers:=True
End Sub
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 34

Expert Comment

by:Dan Craciun
ID: 40010340
@Saqib Husain, Syed: because you need a SUBSTITUTE after the TTC: you need to change "-" to "_"
0
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 250 total points
ID: 40010354
Sorry, I missed that part but that still does not justify the use of regex

Here is an updated macro.

Sub Macro1()
    Range("A:A").Copy Range("B:B")
    Range("B:B").Replace what:="-", replacement:="_"
    Range("B:B").TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
        :=Array(Array(1, 9), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1)), _
        TrailingMinusNumbers:=True
End Sub
0
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 40010367
No, it does not. But I like regular expressions and still think it's cleaner and more readable.

=SUBSTITUTE(RegExpFind($A1,"\w*-\w*",2),"-", "_")
0
 

Author Closing Comment

by:RWayneH
ID: 40016490
Thanks for the help.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
excel file 5 53
Splitting out Data 14 28
Excel Macro - Lookup-Highlight 4 25
Macro 3 22
What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

743 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

13 Experts available now in Live!

Get 1:1 Help Now