VBA Transpose every nth row

Nemo74

New Member
Joined
Mar 22, 2013
Messages
38
Hello all, I'm glad to have found such a great place to learn about excel. I'm the kind of guy who learns from seeing the answer and working backwards. That being said here is my issue:

I one Sheet 1 I have the following:

Columns F2:R2 have values in them. I would like to copy those, transpose them to E2.
THEN SKIP the 13 rows and do the same thing to rows F16:R16, transpose to E17.

This needs to loop until it hits a blank cell. The whole sheet is about 3k rows with the blanks already waiting for the transpose.

I can't get it figured out.

Thanks in advance and I can't wait to see how this works out!
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I think this macro may do what you want...
Rich (BB code):
Sub Tranpose13s()
  Dim Cell As Range
  On Error GoTo NothingInColumnF
  For Each Cell In Columns("F").SpecialCells(xlConstants)
    Cell.Offset(1, -1).Resize(13) = WorksheetFunction.Transpose(Cell.Resize(, 13))
  Next
NothingInColumnF:
End Sub
Note: My code assumes the values in Column F are constants. If those cells should contain formulas instead of constants, then change the constant I have highlighted in red to this... xlFormulas.
 
Last edited:
Upvote 0
Try this code

Sub Macro3()

lastrow = Cells(Rows.Count, "F").End(xlUp).Row

For r = 2 To lastrow

Range("F" & r & ":R" & r).Select
Selection.Copy
If nextr = "" Then Range("E2").Select Else Range("E" & nextr).Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True

Selection.End(xlDown).Select

nextr = ActiveCell.Row + 1


Next r

End Sub
 
Upvote 0
I think this macro may do what you want...
Code:
Sub Tranpose13s()
  Dim Cell As Range
  On Error GoTo NothingInColumnF
  For Each Cell In Columns("F").SpecialCells(xlConstants)
    Cell.Offset(1, -1).Resize(13) = WorksheetFunction.Transpose(Cell.Resize(, 13))
  Next
NothingInColumnF:
End Sub

Holy cow! I NEVER figured it was that simple! Thank you so much, I'll file this away in the "You can learn from this exmaple" book!

Gosh thanks again.
 
Upvote 0
Holy cow! I NEVER figured it was that simple! Thank you so much, I'll file this away in the "You can learn from this exmaple" book!
You are quite welcome. Just so you know, I added the On Error protection just in case you ran the macro against a blank worksheet (or at least a sheet with nothing in Column F). If you know you will always run the macro against a sheet populated with your data, then you can simplify the macro by removing the On Error and its target Label...
Code:
Sub Tranpose13s()
  Dim Cell As Range
  For Each Cell In Columns("F").SpecialCells(xlConstants)
    Cell.Offset(1, -1).Resize(13) = WorksheetFunction.Transpose(Cell.Resize(, 13))
  Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,388
Messages
6,119,226
Members
448,878
Latest member
Da9l87

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