Converting cells with ;-separated values into vertical list

Rigano

New Member
Joined
Aug 10, 2010
Messages
10
Hello all,

I have a table that contains ;-separated values in cells (or just single values, or blanks).
What I need is a quick method to convert this data into a long list with a cell for each value.

Workaround I have tried are copying all data into wordpad, using find/replace and pasting back values in excel. Another option is to copy the data and use the excel function to split text into cells. Still then I need to make a vertical list of it myself.

What I am looking for is possibly some code to make it work with a single button click, as I need to repeat this procedure often for many columns. All possible values are the same length (3 in example below, 5 in reality).

Example:
Column A:
116;565;159
[empty cell]
118;354
120
etc.

Desired Output:
116
565
159
118
354
120

Thank you very much!
Rigano
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try

Code:
Sub atest()
Dim LR As Long, i As Long, X
Columns("A").SpecialCells(xlCellTypeBlanks).Delete shift:=xlShiftUp
LR = Range("A" & Rows.Count).End(xlUp).Row
Columns("B").Insert
For i = 1 To LR
    If InStr(Range("A" & i).Value, ";") <> 0 Then
        X = Split(Range("A" & i).Value, ";")
        Range("B" & Rows.Count).End(xlUp).Offset(1).Resize(UBound(X) + 1).Value = Application.Transpose(X)
    Else
        Range("B" & Rows.Count).End(xlUp).Offset(1).Value = Range("A" & i).Value
    End If
Next i
Columns("A").Delete
Range("A1").Delete shift:=xlShiftUp
End Sub
 
Upvote 0
Dear VoG,

That looks marvelous. It does exactly what I need.

Is it possible to extend/adapt this so that is does not overwrite but instead writes in an empty column?

I have 18 columns for which I need to repeat this, I would prefer to have the data in column A-R intact, and make it so that the values from A are written in S, B in T, C in U, etc.

Would that be feasible?

Kind regards,
Rigano
 
Upvote 0
Try this

Code:
Sub atest()
Dim LR As Long, i As Long, j As Long, X
For j = 1 To 18
    LR = Cells(Rows.Count, j).End(xlUp).Row
    For i = 1 To LR
        If Cells(i, j).Value <> "" Then
            If InStr(Cells(i, j).Value, ";") <> 0 Then
                X = Split(Cells(i, j).Value, ";")
                Cells(Rows.Count, j + 18).End(xlUp).Offset(1).Resize(UBound(X) + 1).Value = Application.Transpose(X)
            Else
                Cells(Rows.Count, j + 18).End(xlUp).Offset(1).Value = Cells(i, j).Value
            End If
        End If
    Next i
Next j
End Sub
 
Upvote 0

Forum statistics

Threads
1,225,071
Messages
6,182,685
Members
453,132
Latest member
nsnodgrass73

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top