Results 1 to 28 of 28

Merge cells in corresponding column based on similar values

Threaded View

  1. #10
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Merge cells in corresponding column based on similar values

    See how it works

    
    Option Explicit
    
    Sub MergeData()
    Dim ObjDic   As Object
    Dim WkRg   As Range
    Dim WSOrg  As Worksheet, WSDest  As Worksheet
    Dim F  As Range
    Dim Temp
    Dim J  As Integer
    Const OffCol As Integer = 20
        Set ObjDic = CreateObject("Scripting.Dictionary")
        Set WSOrg = Sheets("Before")
        Set WSDest = Sheets("After")
        
        Set WkRg = WSOrg.UsedRange
        Set WkRg = Intersect(WkRg, WkRg.Offset(3, 0))
        With ObjDic
            For Each F In WkRg.Columns(1).Cells
                If (.exists(F.Value)) Then
                    Temp = .Item(F.Value)
                    For J = 1 To UBound(Temp, 2)
                        If (Not (IsEmpty(F.Offset(0, OffCol + J)))) Then
                            If (Len(Temp(1, J)) = 0) Then
                                Temp(1, J) = F.Offset(0, OffCol + J)
                            Else
                                Temp(1, J) = Temp(1, J) & ", " & F.Offset(0, OffCol + J)
                            End If
                        End If
                    Next J
                    .Item(F.Value) = Temp
                Else
                    .Item(F.Value) = F.Offset(0, OffCol + 1).Resize(1, 4).Value
                End If
            Next F
            WSDest.Cells(3, 1).CurrentRegion.Offset(1, 0).Cells.ClearContents
            WSDest.Range("A4").Resize(.Count, 1) = Application.Transpose(.keys)
            WSDest.Range("W4").Resize(.Count, 4) = Application.Transpose(Application.Transpose(.items))
        End With
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA to Merge Cells based on Other Column Values
    By meystingray in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-19-2014, 11:10 AM
  2. Merge values from column in one cell, based on duplicates in another column
    By Rawland_Hustle in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-24-2014, 11:04 AM
  3. Running Macro with Do Loop of similar based on values in a Column
    By fishycarl in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-11-2013, 03:50 AM
  4. How to transpose a column based on similar values
    By tdunford7 in forum Excel General
    Replies: 4
    Last Post: 02-28-2012, 12:51 AM
  5. [SOLVED] Copying cells with similar column values
    By mohd21uk via OfficeKB.com in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 05-15-2006, 04:35 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1