Text to columns then consolidated into one column

aka_krakur

Active Member
Joined
Jan 31, 2006
Messages
438
I have a column of data that is not consistent except for codes are separated by a semicolon. Up until now I manually convert text to table by separating by semicolon in Data, Text to columns in excel.
then I have to do a bunch of sorting becuase end result I need all these codes into one column. I have pasted below the examples and then finally the end result that I need.
Book2
ABCDEF
1REPORTED_DEV_CLARIFICATIONREPORTED_DEV_CLARIFICATION1REPORTED_DEV_CLARIFICATION2REPORTED_DEV_CLARIFICATION3REPORTED_DEV_CLARIFICATION4REPORTED_DEV_CLARIFICATION5
21393-N/A;1528-FilterBasket;1393-N/A1528-FilterBasket
31586-Core;2578-N/A;1586-Core2578-N/A
41586-Tip;1586-Tip
52578-DeviceComponent;2578-DeviceComponent
62578-Stent;2578-Stent
71528-FilterBasket;1586-Core;1586-FilterBasket;2578-FilterBasket;1670-AgainstResistance;1528-FilterBasket1586-Core1586-FilterBasket2578-FilterBasket1670-AgainstResistance
81339-Tip;1339-Tip
91339-Shaft;1467-IntroducerSheath;1339-Shaft1467-IntroducerSheath
Sheet1


END RESULT
Book2
ABCD
13REPORTED_DEV_CLARIFICATION
141393-N/A
151586-Core
161586-Tip
172578-DeviceComponent
182578-Stent
191528-FilterBasket
201339-Tip
211339-Shaft
221528-FilterBasket
232578-N/A
241586-Core
251467-IntroducerSheath
261586-FilterBasket
272578-FilterBasket
281670-AgainstResistance
Sheet1


Can someone help me with this...possibly a macro that loops until all codes in Column A are separated by semicolon then put on their own distinctive row into one column.

Thanks
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hi aka_krakur

Please try:
Code:
Sub SplitDev()
Dim lrow As Long, rCell As Range, vDev

Columns("B").Insert
Range("A1").Copy Destination:=Range("B1")
lrow = 2
For Each rCell In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
    For Each vDev In Split(rCell, ";")
        If Trim(vDev) <> "" Then
            Range("B" & lrow).Value = Trim(vDev)
            lrow = lrow + 1
        End If
    Next vDev
Next rCell
Columns("A").Delete
End Sub

Hope this helps
PGC
 
Upvote 0
Thanks, looks like it worked. I have to validate by doing it manually; but it looks good.

This might be asking a lot; but before the codes are broken up and separated and put under one column, would there be a way to associate another column with the month-year as there is another column that lists what month-year (MMM-YY) the code happened in.
Here's an example:
Book4
NOPQ
1MONTH_SORTREPORTED_DEVICE_CODE
2Jan-062524;
3Feb-062524;
4Feb-061393;1528;
5Mar-061586;2578;
6Mar-061586;
7Apr-062578;
8May-062524;
9May-061601;
10Jun-062578;
11Jun-062578;
12Jun-06X100;
13Jun-061528;1586;1586;2578;1670;
Sheet1


I know the codes look different; but this is how they truly are. (Still separated by Semicolon. Now I would need them still separated but still associated with they're month-year.
Here's how I would need the end result. (Verified by manual process)
Book5
PQRS
1MONTH_SORTREPORTED_DEVICE_CODE
21/1/20062524
32/1/20062524
42/1/20061393
53/1/20061586
63/1/20061586
74/1/20062578
85/1/20062524
95/1/20061601
106/1/20062578
116/1/20062578
126/1/2006X100
136/1/20061528
142/1/20061528
153/1/20062578
166/1/20061586
176/1/20061586
186/1/20062578
196/1/20061670
Sheet1
 
Upvote 0
Hi

What are the values in the column N.

is Jan-06

- a text "Jan-06"
or
- an excel date like 2006-01-01 with a custom format string "mmm-yy"

Kind regards
PGC
 
Upvote 0
Hi again

Assuming the MONTH_SORT in column A and the REPORTED_DEVICE_CODE in column B, try:

Code:
Sub SplitDev()
Dim lrow As Long, rCell As Range, vDev

Columns("C:D").Insert
Range("A1:B1").Copy Destination:=Range("C1")
lrow = 2
For Each rCell In Range("B2:B" & Range("B" & Rows.Count).End(xlUp).Row)
    For Each vDev In Split(rCell, ";")
        If Trim(vDev) <> "" Then
            Range("C" & lrow).Value = rCell.Offset(, -1)
            Range("D" & lrow).Value = Trim(vDev)
            lrow = lrow + 1
        End If
    Next vDev
Next rCell
Columns("A:B").Delete
End Sub

Hope this helps
PGC
 
Upvote 0
WORKS LIKE A CHARM...THANKS!!
Only glitch that is mainly cosmetic. Is my data starts on row 19 (well, actually headers start on row 18)
I tried changing some of the values but can't get it right...any more suggestions?
 
Upvote 0
Hi

Assuming the MONTH_SORT in column A and the REPORTED_DEVICE_CODE in column B, with the headers in row 18 and the data starting in row 19, try:

Code:
Sub SplitDev()
Dim lrow As Long, rCell As Range, vDev

Columns("C:D").Insert
Range("A18:B18").Copy Destination:=Range("C18")
lrow = 19
For Each rCell In Range("B19:B" & Range("B" & Rows.Count).End(xlUp).Row)
    For Each vDev In Split(rCell, ";")
        If Trim(vDev) <> "" Then
            Range("C" & lrow).Value = rCell.Offset(, -1)
            Range("D" & lrow).Value = Trim(vDev)
            lrow = lrow + 1
        End If
    Next vDev
Next rCell
Columns("A:B").Delete
End Sub

Hope this helps
PGC
 
Upvote 0
Thanks, you've been a big help....it's going from taking like 4 hours to 10 seconds!!! awesome!!!

Any chance you can take a look at my other Post on the Excel Board

http://www.mrexcel.com/board2/viewtopic.php?t=257895

I'm having a heck of a time trying to extract dates from a text string (well, if you read, I've accomplished it sort of, but when there's multiple dates having problems).
 
Upvote 0

Forum statistics

Threads
1,214,808
Messages
6,121,686
Members
449,048
Latest member
81jamesacct

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