+ Reply to Thread
Results 1 to 21 of 21

Moving data from a row to column based on dup

Hybrid View

  1. #1
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Moving data from a row to column based on dup

    I think creating more than four contacts could be possible, but before we move further I just need to confirm your desired outcome.

    Could you adjust your sample data to contain two tabs. One with the original data (no extra columns) and then a tab with the final results in the format you desire?
    HTH
    Regards, Jeff

  2. #2
    Registered User
    Join Date
    12-31-2010
    Location
    Ottawa, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Moving data from a row to column based on dup

    Quote Originally Posted by jeffreybrown View Post
    I think creating more than four contacts could be possible, but before we move further I just need to confirm your desired outcome.

    Could you adjust your sample data to contain two tabs. One with the original data (no extra columns) and then a tab with the final results in the format you desire?
    Hey Jeff,

    Again - thanks for your help, this is awesome.

    I have attached the updated sheet with the 2 tabs. The first is the *raw* data and the 2nd would be the outcome I would like to see. Again, if it's possible to create more contact areas if a company should have more (I know one company I have has 23 contacts...) that would be awesome. If not, if we could have space for 5 that would be perfect.
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    12-31-2010
    Location
    Ottawa, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Moving data from a row to column based on dup

    Woops. Just re-read your request.

    I have re-attached, but on the raw file I have removed the blank contact areas.

    Please see attached.
    Attached Files Attached Files

  4. #4
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Moving data from a row to column based on dup

    Okay give this a try. Please test on some test data before running macro. Best way, make a copy of the data tab and then run the macro on that sheet.

    I have not tested this past the amount of data included, but in awhile I will work on getting the rest done so it is more dynamic. Have to leave right now. Let me know what you think?
    Attached Files Attached Files

  5. #5
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Moving data from a row to column based on dup

    This seems to cover it.

    Added a timer to the macro and tested with 3600 rows of data and it came out ok.

    Note: Remember test out on test data before the real thing.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    12-31-2010
    Location
    Ottawa, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Moving data from a row to column based on dup

    Quote Originally Posted by jeffreybrown View Post
    This seems to cover it.

    Added a timer to the macro and tested with 3600 rows of data and it came out ok.

    Note: Remember test out on test data before the real thing.
    Hey Jeff,

    Sorry for the late response, I was off for a bit.

    Looks like it's 99% of the way there. I have given you a piece of the data. There are 2 spreadsheets. First has the test data (50 lines, multiple companies / employees) and the second has the outcome. It is moving the data but it appears it is not moving it to the outcome tab, only overwriting the data tab. Also, some of it doesn't appear to be going into the right columns (Contact 3 might have a phone number).

    If you had the solution to these last few things you would be saving me an amazing amount of time on a weekly basis.

    Thanks for all your hard work on this till now.

    Cheers,
    Attached Files Attached Files

  7. #7
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Moving data from a row to column based on dup

    Okay I think this does it; however, it doesn't quite seem to match your outcome. If this does not work 100% for you then I need some exact details as to what is not transferring correctly.

    As I understand it you want to keep unique by company. I count 24 unique companies. On your Outcome workbook you show Douglas Shipman against company Compumail Corp, but on the Test data workbook he is part of the Wethersfield Historical Society Inc company. Which is correct?

    Also, when you run this macro it will create a copy of the Raw Data sheet and call it Raw Data Test and that's where the results will be. The Raw Data sheet will stay intact.

    Please let me know specifics about where error might arise.

    Sub MoveData()
        Dim _
            ws      As Worksheet, _
            Rng     As Range, _
            LR      As Long, _
            LC      As Long, _
            i       As Long, _
            s       As Long, _
            x       As Long, _
            j       As Long: j = 3
            
            Sheets.Add After:=Sheets(Sheets.Count)
            Set ws = ActiveSheet
            ws.Name = "Raw Data Test"
            Sheets("Raw Data").UsedRange.Copy Sheets("Raw Data Test").Range("A1")
            
        With ws
        Application.ScreenUpdating = False
            LR = .Cells(.Rows.Count, "A").End(xlUp).Row
            Set Rng = Range("A2:A" & LR)
            For i = 3 To LR
                If .Cells(i - 1, 1) <> .Cells(i - 2, 1) Then
                    If j <> 3 Then j = j + 1
                    s = Application.WorksheetFunction.CountIf(Rng, .Cells(i - 1, 1).Text) - 1
                    For x = 1 To s
                        LC = .Cells(i - 1, .Columns.Count).End(xlToLeft).Column + 1
                        .Cells(1, LC).Resize(, 5).Value = _
                        Array("First Name" & x + 1, "Last Name" & x + 1, "Title" & x + 1, _
                                        "Contact Number" & x + 1, "Contact Email" & x + 1)
                        .Cells(j, 2).Resize(, 5).Copy .Cells(i - 1, LC)
                        j = j + 1
                    Next x
                End If
            Next i
            .Range("A1").CurrentRegion.RemoveDuplicates Columns:=1, Header:=xlYes
            .UsedRange.Columns.AutoFit
            LC = .Cells(1, .Columns.Count).End(xlToLeft).Column + 1
            .Columns("G:S").Cut
            .Columns(LC).Insert Shift:=xlToRight
            Application.Goto [A1]
            Application.ScreenUpdating = True
        End With
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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