+ Reply to Thread
Results 1 to 6 of 6

Moving data from Rows to columns and delete repeated rows

Hybrid View

  1. #1
    Registered User
    Join Date
    12-04-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    5

    Moving data from Rows to columns and delete repeated rows

    Need help removing duplicate rows and move other data frm rows to columns.xlsx
    Hello all,
    I am attaching a sample excel sheet showing what I need to do.
    In the first tab, I have a list that includes duplicate rows (first column only). I want to remove those duplicate rows but I don't want to lose the data in the following columns which can be unique or duplicates as well.
    Please see the desired result tab in the sheet to get an idea of what I am looking for as the end result.

    Keep in mind that the actual source file I am working with could have up to 50000 row, and the expected results could be around 2000 rows. So nothing can be done manually.

    Thanks all in advance,
    Mike
    Last edited by JBeaucaire; 04-17-2014 at 01:08 AM.

  2. #2
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: Moving data from Rows to columns and delete repeated rows

    find attached!

    formula used in this sheet are array formulas ! you need to copy paste the formula then hold control and shift together and then hit enter instead of just pressing enter.

    don't delete helper columns as they are used to fetch the data !

    all formulas has been adjusted to work with 50000 rows.

    it may take some time for the formula to calculate.
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    WANT TO SAY THANKS, HIT ADD REPUTATION (*) AT THE BOTTOM LEFT CORNER OF THE POST

    More we learn about excel, more it shows us, how less we know about it.

    for chemistry
    https://www.youtube.com/c/chemistrybyshivaansh

  3. #3
    Registered User
    Join Date
    12-04-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    5

    Re: Moving data from Rows to columns and delete repeated rows

    Hemesh,
    Thank you so much this is very helpful.

    But this formulas will only work if data entered under the Location, Interface, Class are numbers. I tried to type some text there as a test but the results didn't include the text. It actually interrupted the formulas.
    Is there anyway to modify your formulas to work whether the entries are numerical or texts?
    Thanks,
    MA

  4. #4
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Moving data from Rows to columns and delete repeated rows

    Try this on a small amount of data first:-
    Results on sheet1
    Sub MG18Apr08
    Dim Dic         As Object
    Dim rDn         As Long
    Dim Q
    Dim nRay()
    Dim Ray
    Dim c           As Long
    Dim Nam         As String
    Dim Col         As Integer
    Dim n           As Long
    Dim Omax        As Long
    Dim ColNum      As Integer
        ColNum = 1
        Ray = Cells(1).CurrentRegion.Value
    For Col = 2 To 4
            Set Dic = CreateObject("Scripting.Dictionary")
            Dic.CompareMode = 1
            
            For rDn = 2 To UBound(Ray, 1)
                If Not Dic.exists(Ray(rDn, 1)) Then
                    Set Dic(Ray(rDn, 1)) = CreateObject("Scripting.Dictionary")
                End If
                If Not Dic(Ray(rDn, 1)).exists(Ray(rDn, Col)) Then
                   
                   Dic(Ray(rDn, 1))(Ray(rDn, Col)) = Ray(1, Col)
                End If
           Next rDn
    
    Dim k       As Variant
    Dim p       As Variant
    Dim Tg      As Integer
    Dim Tem     As Integer
    c = 1
    For Each k In Dic.keys
      c = c + 1
        n = IIf(Col = 2, 1, 0)
        For Each p In Dic.Item(k)
            n = n + 1
            Tg = IIf(Col = 2, n - 1, n)
            If n >= Tem Then ReDim Preserve nRay(1 To Dic.Count + 1, 1 To n)
                If Col = 2 Then nRay(c, 1) = k: nRay(1, 1) = "nAME"
                    nRay(1, n) = Dic(k).Item(p) & Tg
                        nRay(c, n) = p
                            Tem = UBound(nRay, 2)
        Next p
    Omax = Application.Max(Omax, n)
    Next k
        Sheets("Sheet1").Cells(1, ColNum).Resize(c, Omax) = nRay
            ColNum = ColNum + Omax
                Omax = 0
                    Erase nRay
                        Tem = 0
    Next Col
    End Sub
    Regards Mick

  5. #5
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: Moving data from Rows to columns and delete repeated rows

    Sorry for the delayed reply I saw your post today. I will go through the same and will post the reply ASAP

  6. #6
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: Moving data from Rows to columns and delete repeated rows

    Find attached ! I have updated the formula for text Entries. It was throwing error because of frequency function as this function doesn't accept the text values.

    Hope this helps!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Move data on duplicate rows (different columns) to one row and delete extra rows?
    By Sagwa in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-01-2014, 08:25 AM
  2. Delete repeated rows in a list
    By jluiz in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-14-2013, 03:55 PM
  3. Delete duplicate rows with same data in certain columns for million rows
    By amlan009 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-08-2012, 12:53 AM
  4. Replies: 6
    Last Post: 07-05-2011, 07:18 PM
  5. delete rows if value in column D is repeated
    By DKY in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-12-2005, 06:07 PM

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