Microsoft Excel
--
Questions
--
Followers
Top Experts
Thanks in advanced!
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
I'm confused. ย On what basis should the entries associated with 12R096-3 be separated as per your example?
Regards,
Patrick






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
2. Copy-Paste the pivot table.
3. Concatenate. (Refer the attachment)
Hope this helps.
Tils
Sorry, still not making sense. ย In your example, Col B has only 2 distinct values, yet your sample output shows
three groups. ย Why?
FWIW, I am liking tilsant's PT idea...
Patrick

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
be in the same cell.
Item 1 - 2
Item 2 - 2
Item 3 - 1

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Sub ReBorder(r2 As Range)
With r2
.Borders(xlEdgeLeft).LineStyle = xlNone
.Borders(xlEdgeTop).LineStyle = xlNone
.Borders(xlEdgeBottom).LineStyle = xlNone
.Borders(xlEdgeRight).LineStyle = xlNone
.Borders(xlInsideVertical).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
.BorderAround xlContinuous, xlMedium
End With
With r2.Offset(, 1)
.Borders(xlEdgeLeft).LineStyle = xlNone
.Borders(xlEdgeTop).LineStyle = xlNone
.Borders(xlEdgeBottom).LineStyle = xlNone
.Borders(xlEdgeRight).LineStyle = xlNone
.Borders(xlInsideVertical).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
.BorderAround xlContinuous, xlMedium
End With
End Sub
Sub combineme()
Application.ScreenUpdating = False
Dim r As Range, r2 As Range, r3 As Range, r4 As Range, oldVal As String
Set r3 = Sheets("Sheet1").Range("B11") '' << SET TARGET HERE (top left)
Set r4 = Sheets("Sheet1").Range("B2:B7") '' << SET SOURCE HERE
Set r = r4.Cells(1)
oldVal = ""
While r.Row < r4.Row + r4.Rows.Count
Set r2 = r
While r2.Offset(1).Value = r2.Value And r2.Offset(1, 1).Value = r2.Offset(, 1).Value
Set r2 = r2.Offset(1)
Wend
If r.Value = oldVal Then
r3.Value = ""
Else
r3.Value = r.Value
If oldVal > "" Then ReBorder Range(r3.Offset(-1), r3.Offset(-1).End(xlUp))
oldVal = r.Value
End If
r3.Offset(, 1).Value = r.Offset(, 1).Value & " - " & Application.WorksheetFunction.Sum(Range(r, r2).Offset(, 2))
Set r = r2.Offset(1)
Set r3 = r3.Offset(1)
Wend
If oldVal > "" Then ReBorder Range(r3.Offset(-1), r3.Offset(-1).End(xlUp))
Application.ScreenUpdating = True
End Sub
Sub tmp()
For i = ActiveSheet.UsedRange.Rows.Count To 2 Step -1
If Range("A" & i) = "" Then
Range("B" & i - 1) = Range("B" & i - 1) & vbLf & Range("B" & i)
Range("B" & i).EntireRow.Delete
End If
Next
End Sub






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Sub combineme()
Application.ScreenUpdating = False
Sheets(1).Range("B11:C15").ClearContents
Dim r As Range, r2 As Range, r3 As Range, r4 As Range, s As String
Set r3 = Sheets("Sheet1").Range("B11") '' << SET TARGET HERE (top left)
Set r4 = Sheets("Sheet1").Range("B2:B7") '' << SET SOURCE HERE
Set r = r4.Cells(1)
While r.Row < r4.Row + r4.Rows.Count
s = ""
Set r2 = r
While r2.Offset(1).Value = r2.Value
While r2.Offset(1).Value = r2.Value And r2.Offset(1, 1).Value = r2.Offset(, 1).Value
Set r2 = r2.Offset(1)
Wend
s = s & r2.Offset(, 1).Value & " - " & Application.WorksheetFunction.Sum(Range(r, r2).Offset(, 2)) & Chr(10)
Set r2 = r2.Offset(1)
Set r = r2
Wend
s = s & r2.Offset(, 1).Value & " - " & Application.WorksheetFunction.Sum(Range(r, r2).Offset(, 2)) & Chr(10)
Set r = r2.Offset(1)
r3.Value = r.Offset(-1).Value
r3.Offset(, 1).Value = Left(s, Len(s) - 1)
Set r3 = r3.Offset(1)
Wend
Application.ScreenUpdating = True
End Sub
Microsoft Excel
--
Questions
--
Followers
Top Experts
Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.