Automate Grouping of data in a report

Cantrecallmyusername

Board Regular
Joined
May 24, 2021
Messages
50
Office Version
  1. 365
Platform
  1. Windows
Hi there,

On my tab JIRA data I want the column with headers Project Status in Column N copied to the last row along with Column name Key in column A and B to a new Tab called Macro in to cells A6.

Then I need to sort the data by Project Status (A-Z) I will add formulas into cells C6-J6 - I want these dragged to the last row - initially I will use dummy formulas in this case - I can replace.

Every time the value in column A changes (project status) I want an insert of 3 lines. The first line is blank, on the second line in column B add the project status in to the cell and on the third line add in the following headers in the cells going from current cell to the right Item,
Description,
Last Update,
Start Date,
Project Phase,
Target Implementation,
Last Update Date,
RAG,
Project Status

Here is my input data
Book1
ABCDEFGHIJKLMN
1KeyProject Status
21ABC-1Active
32ABC-2Active
43ABC-3Active
54ABC-4Active
65ABC-5Active
76ABC-6Active
87ABC-7Active
98ABC-8Backlog
109ABC-9Backlog
1110ABC-10Backlog
1211ABC-11Backlog
1312ABC-12Backlog
1413ABC-13CA Driven
1514ABC-14CA Driven
1615ABC-15CA Driven
1716ABC-16CA Driven
1817ABC-17CA Driven
1918ABC-18CA Driven
2019ABC-19CA Driven
2120ABC-20GPM Queue
2221ABC-21GPM Queue
2322ABC-22GPM Queue
2423ABC-23GPM Queue
2524ABC-24GPM Queue
2625ABC-25New Change Request
2726ABC-26New Change Request
2827ABC-27New Change Request
2928ABC-28New Change Request
3029ABC-29Pipeline
3130ABC-30Pipeline
3231ABC-31Pipeline
3332ABC-32On Hold
3433ABC-33On Hold
3534ABC-34On Hold
JIRA Data


This is my desired output
Book1
ABCDEFGHIJK
4StatusActive
5ItemDesLast UpdateStart DateProject PhaseTarget ImplementationLast Update DateRAGProject Status
61SEBP_110203040506017181
72SEBP_210203040506017181
83SEBP_310203040506017181
94SEBP_410203040506017181
105SEBP_510203040506017181
116SEBP_610203040506017181
127SEBP_710203040506017181
13
14StatusBacklog
15ItemDesLast UpdateStart DateProject PhaseTarget ImplementationLast Update DateRAGProject Status
168SEBP_810203040506017181
179SEBP_910203040506017181
1810SEBP_1010203040506017181
1911SEBP_1110203040506017181
2012SEBP_1210203040506017181
21
22StatusCA Driven
23ItemDesLast UpdateStart DateProject PhaseTarget ImplementationLast Update DateRAGProject Status
2413SEBP_1310203040506017181
2514SEBP_1410203040506017181
2615SEBP_1510203040506017181
2716SEBP_1610203040506017181
2817SEBP_1710203040506017181
2918SEBP_1810203040506017181
3019SEBP_1910203040506017181
31
32
Macro


I have the below code that does some of this however the headers are off and not repeated in the sheet for me.

VBA Code:
Sub CopyAndOrganizeData()
    Dim wsJIRA As Worksheet
    Dim wsMacro As Worksheet
    Dim lastRowJIRA As Long
    Dim lastRowMacro As Long
    Dim currentStatus As String
    Dim statusRow As Long
    Dim headerRow As Long
    Dim i As Long
    
    ' Set references to the worksheets
    Set wsJIRA = ThisWorkbook.Sheets("JIRA Data")
    Set wsMacro = ThisWorkbook.Sheets("Macro")
    
    ' Find the last row of data in JIRA Data sheet
    lastRowJIRA = wsJIRA.Cells(wsJIRA.Rows.Count, "B").End(xlUp).Row
    
    ' Find the last row of data in Macro sheet
    lastRowMacro = wsMacro.Cells(wsMacro.Rows.Count, "A").End(xlUp).Row + 1
    
    ' Initialize statusRow
    statusRow = lastRowMacro
    
    ' Loop through the data and organize it by status
    For i = 1 To lastRowJIRA
        If wsJIRA.Cells(i, "N").Value <> currentStatus Then
            ' Add a header for the current status
            currentStatus = wsJIRA.Cells(i, "N").Value
            
            ' Add grouping header
            headerRow = lastRowMacro
            wsMacro.Cells(headerRow, 1).Value = "Status"
            wsMacro.Cells(headerRow, 2).Value = "Grouping"
            
            ' Add headers below the grouping header
            headerRow = headerRow + 1
            wsMacro.Cells(headerRow, 3).Value = "Item"
            wsMacro.Cells(headerRow, 4).Value = "Des"
            wsMacro.Cells(headerRow, 5).Value = "Last Update"
            wsMacro.Cells(headerRow, 6).Value = "Start Date"
            wsMacro.Cells(headerRow, 7).Value = "Project Phase"
            wsMacro.Cells(headerRow, 8).Value = "Target Implementation"
            wsMacro.Cells(headerRow, 9).Value = "Last Update Date"
            wsMacro.Cells(headerRow, 10).Value = "RAG"
            wsMacro.Cells(headerRow, 11).Value = "Project Status"
            
            ' Update statusRow for next status
            statusRow = headerRow + 1
            
            lastRowMacro = lastRowMacro + 1 ' Add line spacing
        End If
        
        ' Copy data to Macro sheet
        wsJIRA.Rows(i).Copy wsMacro.Rows(lastRowMacro)
        lastRowMacro = lastRowMacro + 1
    Next i
    
    ' Clean up
    Application.CutCopyMode = False
    Set wsJIRA = Nothing
    Set wsMacro = Nothing
End Sub

Help would be greatly appreciated with this one
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,215,093
Messages
6,123,067
Members
449,090
Latest member
fragment

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