VBA Copy and Paste for data in two columns

  • Hi All,


    Trying to setup VBA to copy duplicate data in column B for each change in record of column A. Essentially, Data from column B will be copied and pasted for each record in column A


    For Example:

    Data Set Desired Outcome
    Column A Column B Column A Column B
    123456 6550661 123456 6550661
    123458 6550155 123456 6550155
    123574 3220868 123456 3220868
    3220059 123456 3220059
    3220860 123456 3220860
    3908385 123456 3908385
    2126834 123456 2126834
    2125658 123456 2125658
    2015208 123456 2015208
    123458 6550661
    123458 6550155
    123458 3220868
    123458 3220059
    123458 3220860
    123458 3908385
    123458 2126834
    123458 2125658
    123458 2015208
    123574 6550661
    123574 6550155
    123574 3220868
    123574 3220059
    123574 3220860
    123574 3908385
    123574 2126834
    123574 2125658
    123574 2015208
  • Here is a VBA solution.


  • Try

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Here is a VBA solution.


    Alan, this worked perfectly, thank you very much for your help!!

  • Try

    This worked very well! Thank you for taking the time out of your day to offer your expertise!

  • And just for good measure, another one to play with.

    Code
    1. Sub Maybe()
    2. Dim x As Long, i As Long
    3. x = Cells(Rows.Count, 2).End(xlUp).Row - 1
    4. For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
    5. With Cells(Rows.Count, 6).End(xlUp).Offset(1).Resize(x)
    6. .Value = Cells(i, 1).Value
    7. .Offset(, 1).Value = Cells(2, 2).Resize(x).Value
    8. End With
    9. Next i
    10. End Sub
  • And another possibility for future consideration maybe.