Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Additional question to video "Transpose Every X Number of Rows in Excel with a Macro - Advanced Transpose Technique"

0

Thanks so much for the reply! I've attached two Excel sheets. The first is the data. Each respondent was supposed to answer 36 questions. There were 300+ respondents total. Instead of each response from each respondent listed vertically, I need each respondent's 36 responses listed horizontally. If you scroll to Column D, you'll see the results I'm getting when I try to apply the macro. As you can see, the results do not include the Likert scale responses or the question number. Maybe the problem is how I'm highlighting my data before pressing Alt F8?

The second attachment is the macro you provided (with the stepvalue changed to 36 for the 36 row-chunks I need transposed). I apologize if I'm not explaining this clearly. I'm new to all this.

Thank you for your expertise and helpfulness.

Answer
Discuss

Discussion

Hi Egeptkween and welcome to the Forum.

I'm not sure I understand what you're trying to do here. Do you have many rows with data in 3 columns, and want to transpose the data to 36 columns (of 12x3 row data)?  

If possible, please edit your question and use the Add Files... button to upload a representative Excel file (without any personal data) to show your existing macro and data. Then we should be able to give specific help.
John_Ru (rep: 6142) Jun 7, '22 at 5:06 pm
Add to Discussion

Answers

0
Selected Answer

Egeptkween

In the attached file, I've copied (and modified) the module from Don's tutorial and made some changes (in bold).

You need to select cells A2:C10189 (you can paste that where the current cell reference is and press "Return") then run the macro in Module1 from VB Project window. State 36 when asked how many rows should be grouped and (after a few seconds) you'll then get "clumps" of 3 rows x36 columns (i.e. the responses for each respondent).

The changes are in bold below (but it's too late here for me to explain fully- essentially I've worked out the number of columns selected, put that in a new variable then adjusted the copy/transpose and row numbers to suit that):

Sub Transpose_N_Rows_of_X_Columns()
' TeachExcel.com

' Make the macro run faster on large data sets.
Application.ScreenUpdating = False

' Do something with the user-selected cells/range.
xRow = Selection.Rows.Count
xCol = Selection.Column
xWidth = Selection.Columns.Count

' The row that the Transposed data will be put into.
nextRow = 1

' Hard-code Column header example
'Range("C1").Value = "Column Header"

' How many rows to Transpose.
StepValue = InputBox("How many rows of " & xWidth & " columns should be grouped together?")

' Loop through the user-selected data using a step value.
For i = 2 To xRow Step StepValue
        ' Copy the data, using the step value to determine the size of
        ' the copied range.
        Cells(i, xCol).Resize(StepValue, xWidth).Copy       
        'Transpose the data.
        Cells(1, xCol).Offset(nextRow, xWidth).PasteSpecial Paste:=xlPasteAll, Transpose:=True

    ' Increment the nextRow value so the copied data goes onto
    ' a new line.
    nextRow = nextRow + xWidth
Next i

' Remove the "copy lines" from the Transposed data.
Application.CutCopyMode = False
' Make Excel function as expected after the macro is finished.
Application.ScreenUpdating = True

End Sub

Hope this works well for you.

Discuss

Discussion

Thanks for selecting my Answer
John_Ru (rep: 6142) Jun 8, '22 at 4:25 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login