How to transpose columns to rows and insert new rows to fill down data in Excel?
In this article, I introduce a VBA code to transpose columns to rows and insert new rows to fill down data as below screenshot shown, if you are interested in this operation, please go to below for more details.
There is no direct way to transpose a range and insert rows to fill down same data, but here I can introduce a VBA code to quickly solve this task.
1. Press Alt + F11 keys to open Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and paste below VBA code to the Module window. See screenshot:
VBA: Transpose and insert rows.
Sub TransposeInsertRows() 'UpdatebyExtendoffice20161125 Dim xRg As Range Dim i As Long, j As Long, k As Long Dim x As Long, y As Long Set xRg = Application.InputBox _ (Prompt:="Range Selection...", _ Title:="Kutools For Excel", Type:=8) Application.ScreenUpdating = False x = xRg(1, 1).Column + 2 y = xRg(1, xRg.Columns.Count).Column For i = xRg(xRg.Rows.Count, 1).Row To xRg(1, 1).Row Step -1 If Cells(i, x) <> "" And Cells(i, x + 1) <> "" Then k = Cells(i, x - 2).End(xlToRight).Column If k > y Then k = y For j = k To x + 1 Step -1 Cells(i + 1, 1).EntireRow.Insert With Cells(i + 1, x - 2) .Value = .Offset(-1, 0) .Offset(0, 1) = .Offset(-1, 1) .Offset(0, 2) = Cells(i, j) End With Cells(i, j).ClearContents Next j End If Next i Application.ScreenUpdating = True End Sub
3. Press F5 key to run the code, and then select the data range you want to transpose and insert rows into the popping dialog. See screenshot:
4. Click OK. And the selected range has been converted as below screenshot shown.
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!