Link to home
Create AccountLog in
Microsoft Excel

Microsoft Excel

--

Questions

--

Followers

Top Experts

Avatar of cd_morris
cd_morris๐Ÿ‡บ๐Ÿ‡ธ

Combine records
I am looking for a way to combine like records an put the resoults in one cell. ย Please see attached file!
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.


Avatar of cd_morriscd_morris๐Ÿ‡บ๐Ÿ‡ธ

ASKER

Sorry forgot to upload file example

TestData.xls

Avatar of Patrick MatthewsPatrick Matthews๐Ÿ‡บ๐Ÿ‡ธ

Hello cd_morris,

I'm confused. ย On what basis should the entries associated with 12R096-3 be separated as per your example?

Regards,

Patrick

Avatar of cd_morriscd_morris๐Ÿ‡บ๐Ÿ‡ธ

ASKER

If there is only entry the one if then only once as is. ย If multiple for a location then a in the exemple

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of tilsanttilsant๐Ÿ‡ฎ๐Ÿ‡ณ

1. Make a pivot table. (Refer the attachment)
2. Copy-Paste the pivot table.
3. Concatenate. (Refer the attachment)


Hope this helps.
Tils
Copy-of-TestData.xls

Avatar of cd_morriscd_morris๐Ÿ‡บ๐Ÿ‡ธ

ASKER

If only one entry fora data point (12R096-3) then there no nothing to do.

Avatar of Patrick MatthewsPatrick Matthews๐Ÿ‡บ๐Ÿ‡ธ

cd_morris,

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

Free T-shirt

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.


Avatar of tilsanttilsant๐Ÿ‡ฎ๐Ÿ‡ณ

i jus realised tht i've made some mistake.

Avatar of tilsanttilsant๐Ÿ‡ฎ๐Ÿ‡ณ

this one is fine i guess..
Copy-of-TestData.xls

Avatar of tilsanttilsant๐Ÿ‡ฎ๐Ÿ‡ณ

In my first attachment, i had put "Count of tmp1" in the "Data" field which i changed to "Sum of tmp2"........ which i hope is what cd_morris wants.

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of cd_morriscd_morris๐Ÿ‡บ๐Ÿ‡ธ

ASKER

Good catch Patrick my mistake. They should
be in the same cell.

Avatar of cd_morriscd_morris๐Ÿ‡บ๐Ÿ‡ธ

ASKER

Tilsant, I undrstand the Pivoit table and the concatenation but items 1, item 2 and item 3 needs to be in the same cell

Avatar of cd_morriscd_morris๐Ÿ‡บ๐Ÿ‡ธ

ASKER

Example C11 would look like this:
Item 1 - 2
Item 2 - 2
Item 3 - 1

Free T-shirt

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.


Avatar of tilsanttilsant๐Ÿ‡ฎ๐Ÿ‡ณ

u intend to "merge" the cells??

Avatar of cyberkiwicyberkiwi๐Ÿ‡ณ๐Ÿ‡ฟ


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

Open in new window


Avatar of tilsanttilsant๐Ÿ‡ฎ๐Ÿ‡ณ

If u intend to merge the cells, then u can copy the table that we created (using the PT and then the concatenation stuff). U can paste this table on some other sheet (cell A1) and run the attached code.

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

Open in new window

Copy-of-TestData.xls

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of cyberkiwicyberkiwi๐Ÿ‡ณ๐Ÿ‡ฟ

Macro to merge from source to target
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

Open in new window


ASKER CERTIFIED SOLUTION
Avatar of Patrick MatthewsPatrick Matthews๐Ÿ‡บ๐Ÿ‡ธ

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account
Microsoft Excel

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.