+ Reply to Thread
Results 1 to 7 of 7

Copy/Paste unique

Hybrid View

  1. #1
    Registered User
    Join Date
    01-11-2021
    Location
    Geneva
    MS-Off Ver
    Office Pro 365Plus
    Posts
    3

    Copy/Paste unique

    Hi everyone,

    Hope you are well!

    I am hoping to find some help for my VBA Macro to help me save time!
    In my excel, I have a list of clients nb and a list of products.
    I must link my clients nb with my products. So that for each products I have a client nb attributed to it into a new column.

    Client list is in column A: from Line 10 up to last non empty row.
    Product list: from range C10 to I10 (number of lines up to last non empty row)

    Here are the instructions for my macro:
    USER TASK: 1. paste in column A clients unique nb (from line 10 to ...)
    2. paste in column C to I unique data for each products (from line 10 to...)

    MACRO:
    3. copy the full range of products from C:I,
    4. past it range L10 to R
    5. add in column S the unique client nb
    6. repeat the same until last unique client nb reached.

    I hope it's clear, hope you can help!

    Thanks a lot,

    Kindest,
    Florian

  2. #2
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365 Version 2501 64-bit
    Posts
    1,465

    Re: Copy/Paste unique

    fmoro,

    Be easier to help if you attach a sample worksheet with a few rows of "dummy" data AND show what you want the output to actually look like?

    Hard to visualise from just a description

    Ochimus

  3. #3
    Registered User
    Join Date
    01-11-2021
    Location
    Geneva
    MS-Off Ver
    Office Pro 365Plus
    Posts
    3

    Re: Copy/Paste unique

    Hello,

    Of course! Please find excel example from attachment.

    Let me know if you have other questions!

    Thanks for your help,

    Kindest,
    Florian
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor
    Join Date
    06-27-2010
    Location
    sYRIA
    MS-Off Ver
    Excel 2013
    Posts
    669

    Re: Copy/Paste unique

    Hi,
    Try
    Option Explicit
    
    Sub test()
    Dim a, b, c As Variant
    Dim lr, l, i As Long
        lr = Cells(Rows.Count, 1).End(xlUp).Row - 9
        a = Cells(10, 1).Resize(lr)
        b = Cells(10, 3).Resize(Cells(Rows.Count, 3).End(xlUp).Row - 9)
        c = Cells(10, 4).Resize(Cells(Rows.Count, 4).End(xlUp).Row - 9, 6)
        For i = 1 To UBound(a)
            Cells(10 + l, 12).Resize(UBound(b)) = b
            Cells(10 + l, 13).Resize(UBound(b)) = a(i, 1)
            Cells(10 + l, 14).Resize(UBound(c), UBound(c, 2)) = c
            l = l + UBound(c)
        Next
    End Sub

  5. #5
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Copy/Paste unique

    Clear the data in columns L:S, leaving the headers only, and run this macro:
    Sub EF1337577()
        Dim i As Long, r As Range
        Application.ScreenUpdating = False
        With ActiveSheet
            With .Range("c10").CurrentRegion
                Set r = .Offset(1).Resize(.Rows.Count - 1)
            End With
            For i = 10 To .Cells(.Rows.Count, 1).End(xlUp).Row
                With .Cells(.Rows.Count, "L").End(xlUp).Offset(1).Resize(r.Rows.Count)
                    .Value = r.Columns(1).Value
                    .Offset(, 1).Value = .Parent.Cells(i, 1).Value
                    .Offset(, 2).Resize(, 6).Value = r.Columns(2).Resize(, 6).Value
                End With
            Next
        End With
        Application.ScreenUpdating = True
    End Sub
    多么想要告诉你 我好喜欢你

  6. #6
    Registered User
    Join Date
    01-11-2021
    Location
    Geneva
    MS-Off Ver
    Office Pro 365Plus
    Posts
    3

    Re: Copy/Paste unique

    Amazing! Thank you so much- I've used Millz and it works like a charm.

  7. #7
    Valued Forum Contributor
    Join Date
    06-27-2010
    Location
    sYRIA
    MS-Off Ver
    Excel 2013
    Posts
    669

    Re: Copy/Paste unique

    Hi again
    I actually Liked Millz code very much
    Concerning the speed for large amount of data this code could be faster!
    Sub test2()
        Dim i As Long, lr, lr2 As Long
        Dim a As Variant
        Application.ScreenUpdating = False
        With ActiveSheet
            a = .Range("A10").CurrentRegion.Resize(, 10)
            lr2 = .Cells(Rows.Count, "c").End(xlUp).Row - 9
            For i = 2 To UBound(a)
                lr = .Cells(Rows.Count, "L").End(xlUp).Row
                Range("L" & lr + 1).Resize(lr2) = Application.Index(a, 0, 3)
                Range("M" & lr + 1).Resize(lr2) = a(i, 1)
                Range("N" & lr + 1).Resize(lr2, 6) = Application.Index(a, 0, Array(4, 5, 6, 7, 8, 9))
            Next
        End With
        Application.ScreenUpdating = True
    End Sub

+ 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] Copy & Paste all unique values from a range
    By liamfrancis2013 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-01-2016, 07:09 AM
  2. Copy unique values and paste to another sheet
    By GEMINI528 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-01-2013, 10:20 AM
  3. A macro to copy & Paste unique value to other cells
    By tantcu in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-26-2013, 07:16 PM
  4. Copy & Paste Unique Values
    By boiler2003 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-06-2012, 09:08 AM
  5. Repeat Copy/Paste for Unique ID
    By dreicer_Jarr in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-13-2009, 12:03 PM
  6. Copy and paste unique values to another worksheet
    By gsrai31 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-28-2009, 11:44 AM
  7. Copy & Paste Unique Cells Values
    By Michael168 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-01-2005, 07:14 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