• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Concatenate based on condition...is it possible with a formula?

PP3321

Active Member
I want to concatenate values based on Month (Column A).

Is it possible with a formula?

*I am using Excel 2010


screenshot.png
 
Code:
Option Explicit

Sub test()
    Dim dic    As Object
    Dim myRange As Range
    Dim r      As Range
 
    Set dic = CreateObject("Scripting.Dictionary")
    Set myRange = Range("A2", Cells(Rows.Count, 1).End(xlUp))
    For Each r In myRange
        dic(r.Value) = dic(r.Value) & r.Offset(, 1).Value & ";"
    Next
    For Each r In myRange
        r.Offset(, 2).Value = dic(r.Value)
    Next
End Sub

I kind of did this with VBA, using Dictionary.

There are 2 problems with VBA:

1. Requirement is to show concatenated value at the top row for each month.

2. My team does not get VBA.
If possible, want to achieve this with a formula...
 
Hi,

Try below code modified your code:

Code:
Option Explicit

Sub test()
    Dim dic    As Object
    Dim myRange As Range
    Dim r      As Range
    Dim j As Long
    Dim cntr As Long
   
    Set dic = CreateObject("Scripting.Dictionary")
    Set myRange = Range("A2", Cells(Rows.Count, 1).End(xlUp))
    For Each r In myRange
        dic(r.Value) = dic(r.Value) & r.Offset(, 1).Value & ";"
    Next
    cntr = 1
    For j = 2 To Cells(Rows.Count, 1).End(xlUp).Row
        If Application.WorksheetFunction.CountIf(Range("A2:A" & j), Range("A" & j)) = 1 Then
            Range("C" & j).Value = Mid(dic(cntr), 1, Len(dic(cntr)) - 1)
            cntr = cntr + 1
        End If
    Next
       
       
       
End Sub

Regards,
 
@Somendra Misra
Thank you!!!!

Your logic is
If count is 1 = first instance

Is that right?

I ran your macro but I got error 5.
When I have time I will look into it.

Thank you!!!!!

screenshot.png
 
Back
Top