Got any Excel/VBA Questions? Free Excel Help
Sub TransposeRows() Dim lRows As Long, lCol As Long Dim rCol As Range Dim lLoop As Long Dim wsStart As Worksheet, wsTrans As Worksheet On Error Resume Next 'Get single column range Set rCol = Application.InputBox(Prompt:="Select single column", _ Title:="TRANSPOSE ROWS", Type:=8) 'Cancelled or non valid range If rCol Is Nothing Then Exit Sub lRows = Application.InputBox(Prompt:="Transpose every x rows", _ Title:="TRANSPOSE ROWS", Type:=2) 'Cancelled If lRows = 0 Then Exit Sub 'Make sure the transpositions will fit If lRows > ActiveSheet.Columns.Count Then MsgBox "Your 'transpose every x rows' exceeds the columns available" Exit Sub End If 'Limit range to used cells lCol = rCol.Column Set rCol = Range(rCol(1, 1), Cells(Rows.Count, lCol).End(xlUp)) 'Set Worksheet variables Set wsStart = ActiveSheet Set wsTrans = Sheets.Add() wsStart.Select 'Loop with step of x and transpose For lLoop = rCol(1, 1).Row To Cells(Rows.Count, lCol).End(xlUp).Row Step lRows Cells(lLoop, lCol).Resize(lRows, 1).Copy wsTrans.Cells(Rows.Count, "A").End(xlUp)(2, 1).PasteSpecial Transpose:=True Application.CutCopyMode = False Next lLoop On Error GoTo 0 End Sub
Index to Excel VBA Code |
See also Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions.
Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.