Solved

How to convert Excel list with commas to Excel list without commas?

Posted on 2014-09-28
8
118 Views
Last Modified: 2014-10-04
I have a list in an Excel file where each row has a column A and a column B.

Here are some example rows in the tab Input from the attached file:
0x0      Hair, Football, Cats, Bees
1x01      Cats, Michael Jackson, Beards, Coffee
1x02      Human Body, Coca-Cola, Morris Dancing, Carrots
1x03      Chickens, London Underground, Queen Elizabeth I, Ancient Egyptians
1x04      George W. Bush, Women, Ants, Olympic Games

Input Data
A new tab should be created as Output with the data converted to:
0x0      Hair
0x0      Football
0x0      Cats
0x0      Bees
1x01      Cats
1x01      Michael Jackson
1x01      Beards
1x01      Coffee

Output DataCreateList.xlsm
0
Comment
Question by:Alex972
  • 4
  • 3
8 Comments
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 500 total points
ID: 40348898
The following VBA subroutine will parse and transpose your data into two columns as requested:
Option Explicit
Sub Parse_and_Transpose()
    Dim rng As Range
    Dim cl As Object
    Dim arrItems As Variant
    Dim strCat As String
    Dim x As Integer
    Dim r As Long
    
    'Remove any existing Output sheet first
    On Error Resume Next
    Application.DisplayAlerts = False
    Sheets("Output").Delete
    
    Sheets.Add After:=Sheets("Input")
    ActiveSheet.Name = "Output"
    Sheets("Input").Select
    
    Set rng = Range("A1", Range("A1").End(xlDown))
    r = 1
    For Each cl In rng
        strCat = cl.Value
        arrItems = Split(cl.Offset(0, 1).Value, ", ")
        For x = 0 To UBound(arrItems)
            Sheets("Output").Cells(r, 1).Value = strCat
            Sheets("Output").Cells(r, 2).Value = arrItems(x)
            r = r + 1
        Next x
        arrItems = Null
    Next cl
    Application.DisplayAlerts = True
    MsgBox "Done."
End Sub

Open in new window


This presumes there are no blank cells in column A.

Example macro-enabled file is attached.

Regards,
-Glenn
EE-CreateList.xlsm
0
 

Author Closing Comment

by:Alex972
ID: 40349108
Exactly what I was looking for.
0
 

Expert Comment

by:Berry Metzger
ID: 40353638
@Alex972
I believe your formulas in F17:F22 are incorrect. The first two formulas are identical as follows...
F17: =D17*VLOOKUP(E17,$A$5:$D$13,3,TRUE)
F18: =D17*VLOOKUP(E17,$A$5:$D$13,3,TRUE)  where it should be: =D17*VLOOKUP(E18,$A$5:$D$13,3,TRUE)
...and so the one-row reference mistake continues for the remainder of the range.
Berry
0
 

Author Comment

by:Alex972
ID: 40360471
Thanks for the notificatios, but I not sure what file this is in regard to. The data file I uploaded doesn't have any formulas.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Expert Comment

by:Berry Metzger
ID: 40360742
It is in reference to your Commission-split Comparison-EDIT-UPDATE.xlsx file that Glenn Ray assisted you with.
0
 

Author Comment

by:Alex972
ID: 40360821
What question is that?
0
 

Expert Comment

by:Berry Metzger
ID: 40361173
Ahaaa! it was not your question, it was by  DEROUCHE solved on 9/30/14.  Don't know how your name got referenced.
Berry
0
 

Author Comment

by:Alex972
ID: 40361207
Ah... all has been revealed. 8^)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to read BOM (Byte Order Mark) from csv file. 4 36
DBF to ... Converter 5 38
Office 2016 Excel Issue 4 26
Excel Save As Status Box will not go away 6 17
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

911 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

22 Experts available now in Live!

Get 1:1 Help Now