VBA To Split adjacent Cells into Rows

kparadise

Board Regular
Joined
Aug 13, 2015
Messages
186
Hello. Very new to VBA (very new). I have a spreadsheet with three columns and need to do some work in the last two columns.

[Sheet 1].[Column A] - ID
[Sheet 1].[Column B] - BUILDING
[Sheet 1].[Column C] - DESC

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD="align: center"]ID
[/TD]
[TD="align: center"]BUILDING
[/TD]
[TD="align: center"]DESC
[/TD]
[/TR]
[TR]
[TD]A
[/TD]
[TD]L1
L2
[/TD]
[TD]Very Large
Extended
[/TD]
[/TR]
[TR]
[TD]B
[/TD]
[TD]L1
L3
L4
[/TD]
[TD]Extra Large
Tiny
Long
[/TD]
[/TR]
[TR]
[TD]C
[/TD]
[TD]S1
[/TD]
[TD]Small
[/TD]
[/TR]
[TR]
[TD]D
[/TD]
[TD]F3
F4
[/TD]
[TD]Fort
Fortable
[/TD]
[/TR]
</tbody>[/TABLE]

Columns B and C can contain multiple 'records' of data which are separated in the same cell by a return sign. For example, ID = A, the text "L1" and "L2" are separated by a paragraph symbol. The same goes for the text in Column C. "Very Large" and "Extended" are separated by a return symbol. The catch he is, the way this system reporting was designed, L1 is connected with Very Large, and L2 is connected with Extended, and L3 is connected with Tiny. So, basically the data which is connected to each other is the same just separated by a paragraph sign.

What I am trying to get VBA for, is to insert as many rows as need to split up the data in columns B and C; and then copy down the ID into the rows below it as well.

ANSWER:

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD="align: center"]ID
[/TD]
[TD="align: center"]BUILDING
[/TD]
[TD="align: center"]DESC
[/TD]
[/TR]
[TR]
[TD]A
[/TD]
[TD]L1
[/TD]
[TD]Very Large
[/TD]
[/TR]
[TR]
[TD]A
[/TD]
[TD]L2
[/TD]
[TD]Extended
[/TD]
[/TR]
[TR]
[TD]B
[/TD]
[TD]L1
[/TD]
[TD]Extra Large
[/TD]
[/TR]
[TR]
[TD]B
[/TD]
[TD]L3
[/TD]
[TD]Tiny
[/TD]
[/TR]
[TR]
[TD]B
[/TD]
[TD]L4
[/TD]
[TD]Long
[/TD]
[/TR]
[TR]
[TD]C
[/TD]
[TD]S1
[/TD]
[TD]Small
[/TD]
[/TR]
[TR]
[TD]D
[/TD]
[TD]F3
[/TD]
[TD]Fort
[/TD]
[/TR]
[TR]
[TD]D
[/TD]
[TD]F4
[/TD]
[TD]Fortable
[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,223,228
Messages
6,170,874
Members
452,363
Latest member
merico17

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