VBA Macro Script to Convert Multiple Rows to Columns in Excel
Step 1: Open Excel with the data you want to change
Start by opening your Excel file containing the data you want to change.
Step 2: Press `Alt + F11` to Open VBA Editor
Press “Alt + F11” to open the VBA Editor, where you can insert code to automate functions.
Step 3: Right-click on the window, Click “Insert,” and select “New Module.”
In the VBA Editor, right-click on any item on the left side (Project Explorer), select “Insert,” and then click “Module.” This creates a space where you can write your VBA code.
Step 4: Write the VBA Code
Copy and paste the provided VBA code into the module. This code helps Excel to convert rows to columns.
Sub TransposeRowsToColumns()
Dim sourceRange As Range
Dim destinationRange As Range
‘Define the source Range (change this to your specific Range)
Set sourceRange = Selection’ Use the currently selected range
‘Define the destination range.
Set destinationRange = sourceRange.Offset(0, sourceRange.Columns.Count + 1)
‘Transpose the data
sourceRange.Copy
destinationRange.PasteSpecial Transpose:=True
‘Clear the clipboard
Application.CutCopyMode = False
End Sub
Step 5: Run the Macro
Close the VBA Editor. Then, press `Alt + F8`, choose “TransposeRowsToColumns,” and click “Run” to execute the macro.
Step 6: Check the Result
After running the macro, check your Excel sheet to see if the rows have been changed to columns as desired.
How to Transpose Data from Rows to Columns
Microsoft Excel is a leading software program by Microsoft that helps you deal with data. It is very certain that, at times, you might want to arrange and manage your data in a different format.
In Excel, “Transposing data” refers to changing rows to columns. If you want to create a table and insert data in rows, you want to display it in columns, or vice versa. Then, the transposing data feature helps you out.
Contact Us