Transpose All data until next blank cell, repeat for all rows

Simon4s

Board Regular
Joined
Sep 22, 2014
Messages
155
Office Version
  1. 2016
  2. 2013
I have a ton of rows and it looks like the following:
Title
ID
Size
URL
Image
Price

BLANK
Title
ID
Size
URL
Image
Price

BLANK

The blank is the divider to the next set of information. I want to transpose the data so that it looks like this:
TitleIDSIZEURLImagePrice
TitleIDSizeURLImagePrice


How can I achieve this? Thanks!
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
This code Transpose Column A to Column D and Next:
VBA Code:
Sub Transpose2()
Dim i As Long, Lr1 As Long, Lr As Long, R As String
Lr = Range("A" & Rows.Count).End(xlUp).Row
R = 1
For i = 1 To Lr
Lr1 = Range("A" & i).End(xlDown).Row
Range("A" & i & ":A" & Lr1).Copy
Range("D" & R).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
i = Lr1 + 1
R = R + 1
Next i
End Sub
 
Upvote 0
Solution
This code Transpose Column A to Column D and Next:
VBA Code:
Sub Transpose2()
Dim i As Long, Lr1 As Long, Lr As Long, R As String
Lr = Range("A" & Rows.Count).End(xlUp).Row
R = 1
For i = 1 To Lr
Lr1 = Range("A" & i).End(xlDown).Row
Range("A" & i & ":A" & Lr1).Copy
Range("D" & R).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
i = Lr1 + 1
R = R + 1
Next i
End Sub
Will this still work if each set of data contains a different number of rows? I forgot to mention that each set of data has between 1-6 tags.
 
Upvote 0
A slight variation to also consider

VBA Code:
Sub Rearrange()
  Dim rA As Range
  
  Application.ScreenUpdating = False
  For Each rA In Columns("A").SpecialCells(xlConstants).Areas
    Range("C" & Rows.Count).End(xlUp).Offset(1).Resize(, rA.Rows.Count).Value = Application.Transpose(rA.Value)
  Next rA
  Application.ScreenUpdating = True
End Sub

My sample data and results

Simon4s.xlsm
ABCDEFGHI
1Title 1
2ID 1Title 1ID 1Size 1URL 1Image 1Price 1
3Size 1Title 2ID 2Size 2URL 2Image 2Price 2
4URL 1Title 3ID 3Size 3
5Image 1Title 4ID 4Size 4URL 4Image 4
6Price 1
7
8Title 2
9ID 2
10Size 2
11URL 2
12Image 2
13Price 2
14
15Title 3
16ID 3
17Size 3
18
19Title 4
20ID 4
21Size 4
22URL 4
23Image 4
24
Sheet1
 
Upvote 0
A slight variation to also consider

VBA Code:
Sub Rearrange()
  Dim rA As Range
 
  Application.ScreenUpdating = False
  For Each rA In Columns("A").SpecialCells(xlConstants).Areas
    Range("C" & Rows.Count).End(xlUp).Offset(1).Resize(, rA.Rows.Count).Value = Application.Transpose(rA.Value)
  Next rA
  Application.ScreenUpdating = True
End Sub

My sample data and results

Simon4s.xlsm
ABCDEFGHI
1Title 1
2ID 1Title 1ID 1Size 1URL 1Image 1Price 1
3Size 1Title 2ID 2Size 2URL 2Image 2Price 2
4URL 1Title 3ID 3Size 3
5Image 1Title 4ID 4Size 4URL 4Image 4
6Price 1
7
8Title 2
9ID 2
10Size 2
11URL 2
12Image 2
13Price 2
14
15Title 3
16ID 3
17Size 3
18
19Title 4
20ID 4
21Size 4
22URL 4
23Image 4
24
Sheet1
This solution worked well but I am getting Run-time error '13': Type mismatch after 56 rows were generated. Any idea why?

Thanks!

1620871210105.png
 
Upvote 0
This code Transpose Column A to Column D and Next:
VBA Code:
Sub Transpose2()
Dim i As Long, Lr1 As Long, Lr As Long, R As String
Lr = Range("A" & Rows.Count).End(xlUp).Row
R = 1
For i = 1 To Lr
Lr1 = Range("A" & i).End(xlDown).Row
Range("A" & i & ":A" & Lr1).Copy
Range("D" & R).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
i = Lr1 + 1
R = R + 1
Next i
End Sub
This is working perfectly!
 
Upvote 0
I am getting Run-time error '13': Type mismatch after 56 rows were generated. Any idea why?
If you click Debug, is the highlighted line the one you have put a break point on in that image?
First thing would be to look at what is in the 56th and 57th blocks of text in column A and see if anything unusual is there.
 
Upvote 0

Forum statistics

Threads
1,223,934
Messages
6,175,491
Members
452,649
Latest member
mr_bhavesh

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