+ Reply to Thread
Results 1 to 3 of 3

Copy/Paste VBA to realign partially duplicated rows of data

  1. #1
    Registered User
    Join Date
    02-28-2019
    Location
    Florida
    MS-Off Ver
    2016
    Posts
    16

    Copy/Paste VBA to realign partially duplicated rows of data

    Hi,

    I am trying to use a macro to sort through rows of data and where two columns are the same on multiple rows, the macro then copies and pastes unique values from other columns onto the same row, in essence to consolidate and realign the data.

    So, in essence, in my example spreadsheet, I am trying to look for where columns H and I are duplicated. If they are duplicated then I want to take the data from columns B, C, D, E, F, G and paste it into the same column in the first of the duplicated rows. Then, if the data in K and L have not yet been repeated within the duplicate rows, I want to copy and paste the contents to M and N (or O and P if M and N are already occupied). Then I want to delete the second of the duplicated rows, since all the unique data from it has been copied to the row above.

    My macro sort of works like I want it to, but not completely. Here are the problems I am having:

    1. When copying and pasting the values in B:G, the macro doesn't work right if a cell containing a value in the first duplicated row is further right than a cell containing a value in the second duplicated row. For example, for purchaser Z, when the macros copies the "x" in B38 and pastes it in B37, it deletes the 1 in E37, bu that 1 needs to remain where it is.

    2. If the data in K and L is the same for multiple duplicated rows, it still copies the values over to M and N. For example, with purchaser P, since K20 and K22 both show "5523" but K21 shows "1491", I only want to copy "1491" to M20 and ignore the "5523" in K22.

    3. The last problem I'm having is that when the macro copies and pastes the values in K and L to M and N, it also pastes them in K and L, overwriting the previous data. So for example, when the macro runs, I will end up with "9201" and "Avocado" from K4 and L4 in cells K2, L2, M2, N2, O2, and P2.

    I have attached the example spreadsheet also with a tab to show what I want the finished product to be after the macro runs. I greatly appreciate any help you are willing to provide with any of these issues!

    Here is my code up to this point:
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by atl57; 11-22-2019 at 12:21 PM.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,595

    Re: Copy/Paste VBA to realign partially duplicated rows of data

    Try
    Please Login or Register  to view this content.
    Last edited by jindon; 11-22-2019 at 01:39 AM.

  3. #3
    Registered User
    Join Date
    02-28-2019
    Location
    Florida
    MS-Off Ver
    2016
    Posts
    16

    Re: Copy/Paste VBA to realign partially duplicated rows of data

    Thank you so much that works much better!!

+ 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. Sorting data to find partially empty rows
    By lcol4188 in forum Excel General
    Replies: 2
    Last Post: 10-17-2017, 01:14 PM
  2. Replies: 1
    Last Post: 10-06-2015, 08:32 AM
  3. Replies: 7
    Last Post: 12-17-2014, 01:31 AM
  4. [SOLVED] where cell data duplicated copy rows to new sheet
    By shaz0503 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-23-2013, 05:54 PM
  5. Replies: 6
    Last Post: 08-18-2012, 05:00 AM
  6. How to realign data in columns to rows?
    By Dougie12. in forum Excel General
    Replies: 4
    Last Post: 02-27-2012, 06:17 PM
  7. Replies: 2
    Last Post: 02-22-2011, 02:07 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