Results 1 to 5 of 5

How to look for duplicates in first column, then copy / paste contents of second column?

Threaded View

  1. #4
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: How to look for duplicates in first column, then copy / paste contents of second colum

    Hello speedyhub,

    Finally I've created code for You - follow below points
    1. sort your source array regarding ID
    2. use provided procedure (copy it into module or to source code of your sheet)
    3. use autofilter for get expected result

    Sub GiveMeTransposeResult()
    'Author: MaczaQ
    Dim sAddr As String, source, tmp, cl As Range, colOffset as Integer
     
    Set source = Range("A3:B20")  '<<<<------------------------------SOURCE-------------------------------------
    'other way to set up source range if you want to select your source data just unhash below code
    'Set source = Selection
    colOffset = source.Columns.Count
     
      With source.Columns(1)
        Set tmp = .Cells(1, 1)
         For Each cl In .Cells
            'all groups excluding last group
            If cl.Value <> tmp.Value And cl.Address <> .Cells(.Cells.Count, 1).Address Then
              sAddr = tmp.Address & ":" & cl.Offset(-1).Address
               arr = Application.Transpose(Range(sAddr).Offset(, 1))
                 If tmp.Address <> cl.Offset(-1).Address Then
                   Range(tmp.Address).Offset(, colOffset).Resize(, UBound(arr)).Value = arr
                 Else
                   Range(tmp.Address).Offset(, colOffset).Value = arr
                 End If
               Set tmp = cl
            End If
           
            'last group
            If cl.Address = .Cells(.Cells.Count, 1).Address Then
             sAddr = tmp.Address & ":" & cl.Address
               arr = Application.Transpose(Range(sAddr).Offset(, 1))
                 If tmp.Address <> cl.Offset(-1).Address Then
                    Range(tmp.Address).Offset(, colOffset).Resize(, UBound(arr)).Value = arr
                 Else
                    Range(tmp.Address).Offset(, colOffset).Value = arr
                 End If
            End If
         Next cl
      End With
    End Sub
    If you will need any more help do not hasitate to post it.
    Last edited by MaczaQ; 03-21-2012 at 08:40 AM. Reason: code tidy up

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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