How to combine multiple rows to one based on group column in excel?

I have one excel file with has details tab with multiple columns. I have"group" column. Based on group column i have to merge some rows to one rows and use the high Priority.
Share PointAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
in order to help you we need a sample workbook.
0
Share PointAuthor Commented:
Example.xlsx

Hi,
 I have attached the sample workbook. I have details and Output tabs. I need to generate the Output tab from detail tab.

Thank you.
0
Martin LissOlder than dirtCommented:
I don't see either a 'details' tab or an 'Output' tab. Do they have different names?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Share PointAuthor Commented:
sample imageMartin,
 I am not sure why you are not able to open Example.xls file. I am attaching sample workbook and also image.
Sample-Book.xlsx
0
Rob HensonFinance AnalystCommented:
See attached.

I have added a column to the source data with following formula:
=IF(D2="",B2,D2)

This adds the Item number where group is blank.

With that data I have then created a Pivot Table to summarise by Priority and Group/Item. This shows different results to your Output as I can't see how you're making the values in your Output.
Sample-Book.xlsx
0
Martin LissOlder than dirtCommented:
I too don't understand why the results should be that way.
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
If I understood your requirement correctly, you may try something like this...
Sub SummarizeData()
Dim sws As Worksheet, dws As Worksheet
Dim x, dict, it, y()
Dim i As Long, j As Long
Dim gp As String
Application.ScreenUpdating = False

Set sws = Sheets("Detail")
Set dws = Sheets("Output")

x = sws.Range("A1").CurrentRegion.Value
Set dict = CreateObject("Scripting.Dictionary")
ReDim y(1 To UBound(x, 1), 1 To 3)

For i = 2 To UBound(x, 1)
    gp = IIf(x(i, 4) <> "", x(i, 4), x(i, 2))
    If Not dict.exists(gp) Then
        dict.Item(gp) = x(i, 1) & "_" & x(i, 3)
    Else
        dict.Item(gp) = IIf(x(i, 1) = "High", "High", Split(dict.Item(gp), "_")(0)) & "_" & Split(dict.Item(gp), "_")(1) + x(i, 3)
    End If
Next i

For Each it In dict.keys
    j = j + 1
    y(j, 1) = Split(dict.Item(it), "_")(0)
    y(j, 2) = it
    y(j, 3) = Split(dict.Item(it), "_")(1)
Next it

dws.Range("A1").CurrentRegion.Offset(1).Clear
dws.Range("A2").Resize(j, 3).Value = y
Application.ScreenUpdating = True
End Sub

Open in new window


In the attached, click the button called "Get Summary" on Output Sheet.
Sample-Book.xlsm
0
Share PointAuthor Commented:
Thank you so much Subodh Tiwari (Neeraj). Looks good. I will test with another data and let you know.

Thanks Again.
0
Share PointAuthor Commented:
Suboth ,
 I think it's working good but i guess i will need your help to implemented with another data (More columns). Sorry i am bad with VBA code. I am attaching another workbook. I will need columns from column E to column P to the Output tab.

 I will need to make sure that below columns has highest value.

Score - Max value (500 is Max)
Risk Level - Very High to  Low (Very high is Max)
Priority  - 0 to 5 (0 is max)

Merge-Workbook.xlsm
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Why didn't you mock up the desired output manually based on your new data? That would help to visualize your requirement more clearly.
Make sure that the mocked up output is correct on Output Sheet.
0
Share PointAuthor Commented:
Suboth,
 I am attaching the another file with mock up. Thank you so much.

Merge-Workbook_v2.xlsm
0
Rob HensonFinance AnalystCommented:
I think a pivot table might still be able to do what you require.
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Okay, give this a try...
In the attached, click on the button "Get Summary" on Output Sheet to run the code.

Sub SummarizeData()
Dim sws As Worksheet, dws As Worksheet
Dim sTbl As ListObject, dTbl As ListObject
Dim dlr As Long, Score As Long, Col As Long
Dim Amt1 As Double, Amt2 As Double, Total As Double
Dim gp As String, AppName As String, Crit As String
Dim Rng As Range, Cell As Range

Application.ScreenUpdating = False

Set sws = Sheets("Detail")
Set dws = Sheets("Output")
Set sTbl = sws.ListObjects(1)
Set dTbl = dws.ListObjects(1)
dTbl.DataBodyRange.Clear

Set Rng = sTbl.DataBodyRange.Columns(9).Cells

For Each Cell In Rng
    If Cell.Value <> "" Then
        gp = Cell.Value
    Else
        AppName = Cell.Offset(0, -1).Value
    End If
    
    Col = IIf(gp <> "", 9, 8)
    Crit = IIf(gp <> "", gp, AppName)
    
    sTbl.Range.AutoFilter
    If Application.CountIf(dTbl.DataBodyRange.Columns(9), Crit) = 0 Then
        sTbl.Range.AutoFilter field:=Col, Criteria1:=Crit
        Score = Application.Max(sTbl.DataBodyRange.Columns(1).SpecialCells(xlCellTypeVisible))
        Amt1 = Application.Sum(sTbl.DataBodyRange.Columns(10).SpecialCells(xlCellTypeVisible))
        Amt2 = Application.Sum(sTbl.DataBodyRange.Columns(11).SpecialCells(xlCellTypeVisible))
        Total = Application.Sum(sTbl.DataBodyRange.Columns(12).SpecialCells(xlCellTypeVisible))
        If dws.Range("E4") = "" Then
            dlr = 4
        Else
            dlr = dTbl.DataBodyRange.Columns(5).Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
        End If
        dws.Range("E" & dlr).Value = Score
        dws.Range("F" & dlr).Value = sTbl.DataBodyRange.Columns(2).SpecialCells(xlCellTypeVisible).Cells(1).Value
        dws.Range("G" & dlr).Value = sTbl.DataBodyRange.Columns(3).SpecialCells(xlCellTypeVisible).Cells(1).Value
        dws.Range("H" & dlr).Value = sTbl.DataBodyRange.Columns(4).SpecialCells(xlCellTypeVisible).Cells(1).Value
        dws.Range("I" & dlr).Value = sTbl.DataBodyRange.Columns(5).SpecialCells(xlCellTypeVisible).Cells(1).Value
        dws.Range("J" & dlr).Value = sTbl.DataBodyRange.Columns(6).SpecialCells(xlCellTypeVisible).Cells(1).Value
        dws.Range("L" & dlr).Value = sTbl.DataBodyRange.Columns(8).SpecialCells(xlCellTypeVisible).Cells(1).Value
        dws.Range("M" & dlr).Value = IIf(gp <> "", gp, AppName)
        dws.Range("N" & dlr).Value = Amt1
        dws.Range("O" & dlr).Value = Amt2
        dws.Range("P" & dlr).Value = Total
    End If
    gp = ""
    AppName = ""
    Score = 0
    Amt1 = 0
    Amt2 = 0
    Total = 0
Next Cell

sTbl.Range.AutoFilter

Application.ScreenUpdating = True
End Sub

Open in new window

Merge-Workbook_v2.xlsm
0
Share PointAuthor Commented:
Hi,
 It's very close. Somehow ABCID column is not populating and Priority column may have lower number. Application name column not require in Output tab (I forgot to remove).

Group1 Example
Thank you so much helping me.
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Okay, please check the attached.
Merge-Workbook_v3.xlsm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Share PointAuthor Commented:
Awesome. That's what i needed. Thank you so much.
0
Share PointAuthor Commented:
Thank you.
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome! Glad it worked as desired.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.