Excel Pivot Table "Insert Column"

sirdylan

New Member
Joined
Oct 9, 2019
Messages
2
Hello,


I have the results of a survey in an Excel spreadsheet, like this:

Question

<tbody>
</tbody>
Grade

<tbody>
</tbody>
StrVal

<tbody>
</tbody>
Flowers and Decoration Team

<tbody>
</tbody>
-1

<tbody>
</tbody>
N/A

<tbody>
</tbody>
******* and Fellowship Team

<tbody>
</tbody>
5

<tbody>
</tbody>
Excellent

<tbody>
</tbody>

<tbody>
</tbody>



and i need to rearrange like this:

Flowers and Decoration Team

<tbody>
</tbody>
Comments

<tbody>
</tbody>
******* and Fellowship Team

<tbody>
</tbody>
Comments2

<tbody>
</tbody>
-1

<tbody>
</tbody>
N/A

<tbody>
</tbody>
5

<tbody>
</tbody>
Excellent

<tbody>
</tbody>



I need to automate this process with macros, i was thinking using pivot table but i can't figure out how to bring Comments Column after every question.Any suggestion?




Thanks!
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Start this code on the (one) sheet containing data.
The code will have to be tweaked if you have multiple sheets to process.
If this is the case, please provide information about those sheets.

Code:
Sub RearrangeData()

    Dim lLastRow As Long
    Dim lRowIndex As Long
    Dim lColIndex As Long
    Dim lWriteRow As Long
    Dim sWorksheet As String
    Dim sDataSheet As String
    
    sDataSheet = ActiveSheet.Name
    
    'Create new sheet to hold changed data
    sWorksheet = "New Data"
    On Error Resume Next
    Application.DisplayAlerts = False
    Worksheets(sWorksheet).Delete
    Application.DisplayAlerts = True
    On Error GoTo 0
    Worksheets.Add(After:=Sheets(Sheets.Count)).Name = sWorksheet 'After last
    
    With Worksheets(sWorksheet)
        lWriteRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
    End With
    
    With Worksheets(sDataSheet)
        lLastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
        For lRowIndex = 2 To lLastRow
            lColIndex = 1 + (3 * (lRowIndex - 2))
            Range(.Cells(lRowIndex, 1), .Cells(lRowIndex, 3)).Copy _
                Destination:=Worksheets(sWorksheet).Cells(lWriteRow, lColIndex)
        Next
        
    End With
    With Worksheets(sWorksheet)
        .UsedRange.ColumnWidth = 50
        .UsedRange.Columns.AutoFit
        .UsedRange.Rows.AutoFit
    End With
End Sub
 
Upvote 0
Thanks for reply, it's helped me a lot, but i can t figure out how to skip Grade Column --> here ->

With Worksheets(sDataSheet) lLastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
For lRowIndex = 2 To lLastRow
lColIndex = 1 + (3 * (lRowIndex - 2))
Range(.Cells(lRowIndex, 1), .Cells(lRowIndex, 3)).Copy _
Destination:=Worksheets(sWorksheet).Cells(lWriteRow, lColIndex)
 
Upvote 0
The grade column header did not appear in your desired output, but the values did so I included them. If you only want to extract the questions and comments replace the lines in post #3 with:

Code:
    With Worksheets(sDataSheet)
        lLastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
        For lRowIndex = 2 To lLastRow
            lColIndex = 1 + (2 * (lRowIndex - 2))
            .Cells(lRowIndex, 1).Copy _
                Destination:=Worksheets(sWorksheet).Cells(lWriteRow, lColIndex)
            .Cells(lRowIndex, 3).Copy _
                Destination:=Worksheets(sWorksheet).Cells(lWriteRow, lColIndex + 1)
 
Upvote 0

Forum statistics

Threads
1,214,630
Messages
6,120,634
Members
448,973
Latest member
ChristineC

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