Transpose from cell to multiple rows

DTMHibbert

New Member
Joined
Oct 4, 2017
Messages
6
Hi all,

Im looking for a way using VBA code to transpose data contained in one cell separated by ";" to multiple rows. Below is an example of what im trying to achieve

Event ID Day Start End Room
1 Monday 09:00 11:00 Room 1; Room 2; Room 3; Room 4
1 Monday 09:00 11:00 Room 1; Room 2; Room 3; Room 4
1 Monday 09:00 11:00 Room 1; Room 2; Room 3; Room 4
1 Monday 09:00 11:00 Room 1; Room 2; Room 3; Room 4
2 Tuesday 15:00 16:00 Room 1; Room 2
2 Tuesday 15:00 16:00 Room 1; Room 2
3 Wednesday 12:00 14:00 Room 1; Room 2; Room 3
3 Wednesday 12:00 14:00 Room 1; Room 2; Room 3
3 Wednesday 12:00 14:00 Room 1; Room 2; Room 3

Event ID Day Start End Room
1 Monday 09:00 11:00 Room 1
1 Monday 09:00 11:00 Room 2
1 Monday 09:00 11:00 Room 3
1 Monday 09:00 11:00 Room 4
2 Tuesday 15:00 16:00 Room 1
2 Tuesday 15:00 16:00 Room 2
3 Wednesday 12:00 14:00 Room 1
3 Wednesday 12:00 14:00 Room 2
3 Wednesday 12:00 14:00 Room 3

As you can see the data in the room column in all combined into one cell however it does produce duplicate rows for each room used. (Event 1 has 4 rows because it has rooms being used). Some events would only have 1 row while some larger events could have roughly 30/40

I did produce a vba script based of something i found online but i have since lost this and cannot find the source again.

Thanks guys.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi, welcome to the forum!

I guess it Depends on how often you needs to do this and how much data is involved - but maybe you could make use of a formula based option:


Excel 2013/2016
ABCDEF
1IDDayStartEndRoom ListSeperated
21Monday09:0011:00Room 1; Room 2; Room 3; Room 4Room 1
31Monday09:0011:00Room 1; Room 2; Room 3; Room 4Room 2
41Monday09:0011:00Room 1; Room 2; Room 3; Room 4Room 3
51Monday09:0011:00Room 1; Room 2; Room 3; Room 4Room 4
62Tuesday15:0016:00Room 1; Room 2Room 1
72Tuesday15:0016:00Room 1; Room 2Room 2
83Wednesd12:0014:00Room 1; Room 2; Room 3Room 1
93Wednesd12:0014:00Room 1; Room 2; Room 3Room 2
103Wednesd12:0014:00Room 1; Room 2; Room 3Room 3
Sheet1
Cell Formulas
RangeFormula
F2=TRIM(MID(SUBSTITUTE(E2,";",REPT(" ",99)),COUNTIF(A$2:A2,A2)*99-98,99))
 
Upvote 0
well i feel i bit daft now as i have just taken the formula and dumped it into my spreadsheet and realised it doesn't work because in my actual export from the system we use it does produce an Event ID.

I did try your formula on the example i gave and it works perfectly so thanks very much that and speedy reply. Can this be adapted?

in any one export we have up to 100,000 rows of data and this would be used weekly.

Thanks
 
Upvote 0
it doesn't work because in my actual export from the system we use it does produce an Event ID.

Hi, i'm not sure what you mean here - maybe you can re-post some sample data that accurately reflects your export - be sure to also include what the expected results should look like.

in any one export we have up to 100,000 rows of data

That's a lot of data and formulas may well prove to be too resource hungry.
 
Upvote 0
The export from our system doesn't contain a column for event ID so an example would be the same as above just without column A.

I think this is why i had a vba script last time.
 
Upvote 0
Hi, try this on a copy of your workbook.

Assumes your room list column is "E" starting on row "2" - the results are output to column "F" - change as appropriate.

Rich (BB code):
Sub m()
'https://www.mrexcel.com/forum/excel-questions/1025647-transpose-cell-multiple-rows.html
Dim a As Variant, i As Long, j As Long, k As Long, Room As Variant
a = Range("E2:E" & Range("E" & Rows.Count).End(xlUp).Row).Value
ReDim b(1 To UBound(a), 1 To 1)
k = 1
For i = 1 To UBound(a)
    Room = Split(a(i, 1), ";")
    For j = 0 To UBound(Room)
        b(k, 1) = Trim(Room(j))
        k = k + 1
    Next j
    i = i + UBound(Room)
Next i
Range("F2").Resize(UBound(a)).Value = b
End Sub
 
Last edited:
Upvote 0
Im getting the following error;

Run-time error '9':
Subscript out of range - when i click debug it highlights this text ---- b(k, 1) = Trim(Room(j))

I changed the column references to like you said.

Thanks
 
Upvote 0
I changed the column references to like you said.

Hi, can you post the amended code and state which column contains the list of rooms and what row they start on.

Subscript out of range - when i click debug it highlights this text ---- b(k, 1) = Trim(Room(j))

When you get the error, can you hit debug and report what this returns from the immediate window.

Code:
? i " | " & k & " | " & a(i,1)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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