Macro Help - Seperating data in a cell split with a comma

Auto667

New Member
Joined
Nov 7, 2014
Messages
7
Hey Everyone,

I have a very large data set (20,000 rows roughly) which I am currently working through that needs to be in a specific format. The data is currently in the following format:

SMM02
04/08/2020​
01:12:16​
Item 1
SMM02
04/08/2020​
00:10:27​
Item 1
SMM02
04/08/2020​
04:05:24​
Item 1,Item 2
SMM02
04/08/2020​
04:14:06​
Item 1
SMM02
22/07/2020​
02:54:43​
Item 2,Item 3
SMM02
04/08/2020​
01:31:38​
Item 2,Item 3, Item 1

and I need to get it into the below format:

SMM02
04/08/2020​
01:12:16​
Item 1
SMM02
04/08/2020​
00:10:27​
Item 1
SMM02
04/08/2020​
04:05:24​
Item 1
SMM02
04/08/2020​
04:05:24​
Item 2
SMM02
04/08/2020​
04:14:06​
Item 1
SMM02
22/07/2020​
02:54:43​
Item 2
SMM02
22/07/2020​
02:54:43​
Item 3
SMM02
04/08/2020​
01:31:38​
Item 2
SMM02
04/08/2020​
01:31:38​
Item 3
SMM02
04/08/2020​
01:31:38​
Item 1

It has been a long time since I have done any VBA programming so my current workflow is: insert a new row, copy and paste the data in the first three columns, copy and pasting the 'Item 1' from a previous entry and then copy and pasting 'Item 2' over the cell that has the two items seperated by a comma.

As you can imaging this is taking a long time. I tired to record a macro but it didn't even give me agreat starting point to try amend something.

The number of items the last column can hold can be up to four.

Any help would really be appreciated.

Thanks in advanced.

Auto
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
I used Power Query/Get and Transform found on the Data Tab

Book6
ABCD
1Column1Column2Column3Column4
2SMM0204/08/202001:12:16Item 1
3SMM0204/08/202000:10:27Item 1
4SMM0204/08/202004:05:24Item 1
5SMM0204/08/202004:05:24Item 2
6SMM0204/08/202004:14:06Item 1
7SMM0222/07/202002:54:43Item 2
8SMM0222/07/202002:54:43Item 3
9SMM0204/08/202001:31:38Item 2
10SMM0204/08/202001:31:38Item 3
11SMM0204/08/202001:31:38 Item 1
Sheet2


Here is the Mcode

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}}),
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Changed Type", {{"Column4", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Column4")
in
    #"Split Column by Delimiter"
 
Upvote 0
I used Power Query/Get and Transform found on the Data Tab

Book6
ABCD
1Column1Column2Column3Column4
2SMM0204/08/202001:12:16Item 1
3SMM0204/08/202000:10:27Item 1
4SMM0204/08/202004:05:24Item 1
5SMM0204/08/202004:05:24Item 2
6SMM0204/08/202004:14:06Item 1
7SMM0222/07/202002:54:43Item 2
8SMM0222/07/202002:54:43Item 3
9SMM0204/08/202001:31:38Item 2
10SMM0204/08/202001:31:38Item 3
11SMM0204/08/202001:31:38 Item 1
Sheet2


Here is the Mcode

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}}),
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Changed Type", {{"Column4", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Column4")
in
    #"Split Column by Delimiter"

Thanks this is perfect!! Really appreciate the quick help :D
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,730
Members
448,987
Latest member
marion_davis

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