Help converting two delimited columns into rows!! Arg!

Mathorik

New Member
Joined
Aug 23, 2013
Messages
4
Hello All!

I have a table with date in two columns (D&E) that have linked delimited data. If column D has 2 values separated by a "|" delimiter, then column E will have the same number of delimited values.
ABCDE
51BobPPV159
61JamesCHH30|16|517|5|8
22StevePPV55|2-14|125
5IvanDCh6-7

<tbody>
</tbody>

I'd like the table to look like:
ABCDE
51Bobppv159
61JamesCHH3017
61JamesCHH165
61JamesCHH58
22StevePPV55-14
22StevePPV2125
5IvanDCh6-7

<tbody>
</tbody>


I'd like a macro to help out, as this process will be occurring weekly with a few thousand rows...
I've seen a few examples on here- but nothing with the two linked columns.
Thank you all in advance for your brain power!

Eric
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
having your data beginning in A1, with headers, try

Code:
[COLOR=darkblue]Sub[/COLOR] trnsp()
[COLOR=darkblue]Dim[/COLOR] vArr [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Variant[/COLOR], tArr [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Variant[/COLOR], x1 [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR], y1 [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR], k1 [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR], spltE, spltD


vArr = Range("A1").CurrentRegion.Value


[COLOR=darkblue]ReDim[/COLOR] tArr(1 [COLOR=darkblue]To[/COLOR] Evaluate(Replace("SUM(LEN(D2:D@)-LEN(SUBSTITUTE(D2:D@,""|"",""""))+1)", "@", Range("A" & Rows.Count).End(xlUp).Row)), 1 [COLOR=darkblue]To[/COLOR] 5)


[COLOR=darkblue]If[/COLOR] [COLOR=darkblue]Not[/COLOR] [COLOR=darkblue]UBound[/COLOR](vArr, 1)-1 = [COLOR=darkblue]UBound[/COLOR](tArr, 1) [COLOR=darkblue]Then[/COLOR]
    k1 = 1
    [COLOR=darkblue]For[/COLOR] x1 = [COLOR=darkblue]LBound[/COLOR](vArr, 1) + 1 [COLOR=darkblue]To[/COLOR] [COLOR=darkblue]UBound[/COLOR](vArr, 1)
        spltD = Split(vArr(x1, 4), "|")
        spltE = Split(vArr(x1, 5), "|")
        [COLOR=darkblue]For[/COLOR] y1 = [COLOR=darkblue]LBound[/COLOR](spltD) [COLOR=darkblue]To[/COLOR] [COLOR=darkblue]UBound[/COLOR](spltD)
            tArr(k1, 1) = vArr(x1, 1)
            tArr(k1, 2) = vArr(x1, 2)
            tArr(k1, 3) = vArr(x1, 3)
            tArr(k1, 4) = spltD(y1)
            tArr(k1, 5) = spltE(y1)
            k1 = 1 + k1
        [COLOR=darkblue]Next[/COLOR] y1
    [COLOR=darkblue]Next[/COLOR] x1
Range("a2").Resize(UBound(tArr, 1), 5).Value = tArr
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]

msgbox "Done"
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
 
Last edited:
Upvote 0
click on Debug and put your cursor on x1 and check its value, then go back to your data and check if column D and E on Row x1 have the same number of "|"
 
Upvote 0
Found a blank value in column E on that line number. Once that was resolved, the program ran without error!
Excellent! Thank you VBA Geek!
 
Upvote 0

Forum statistics

Threads
1,215,529
Messages
6,125,344
Members
449,219
Latest member
Smiqer

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