+ Reply to Thread
Results 1 to 17 of 17

Macro compare cells and paste to columns

  1. #1
    Forum Contributor
    Join Date
    04-03-2012
    Location
    Washington State
    MS-Off Ver
    Excel 365
    Posts
    340

    Macro compare cells and paste to columns

    I am not really sure what to call this code, I found it here in this forum and it works quite well for what I need. The only problem is, I do not understand how the code works and would GREATLY appreciate someones time to write a few lines to explain how this code works (starting from "With CreateObject") so I can learn how to modify it to fit my needs. Many thanks ...

    Please Login or Register  to view this content.

  2. #2
    Forum Contributor
    Join Date
    04-03-2012
    Location
    Washington State
    MS-Off Ver
    Excel 365
    Posts
    340

    Re: Macro compare cells and paste to columns

    What I want to do with this code is make a fourth a column. It seems to find the match from the second column, but if I add a fourth, it gets all messed up. Since I don't understand the code, I am not sure what needs to be changed. Any help would be greatly appreciated.

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro compare cells and paste to columns

    This code is written by Mike7952. I think he is around and should be able to help you out.

  4. #4
    Forum Contributor
    Join Date
    04-03-2012
    Location
    Washington State
    MS-Off Ver
    Excel 365
    Posts
    340

    Re: Macro compare cells and paste to columns

    Thanks AB33, I sent him a request asking for help.

  5. #5
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Macro compare cells and paste to columns

    Can you upload the workbook that your working with?
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  6. #6
    Forum Contributor
    Join Date
    04-03-2012
    Location
    Washington State
    MS-Off Ver
    Excel 365
    Posts
    340

    Re: Macro compare cells and paste to columns

    Thanks for the reply Mike.... Here is the workbook. I need to add a column for Name and Job number. The important column is the "Part Number" column. I have tried a few things to get what I need, but the results have been not so good. Thanks very much for your help.
    Attached Files Attached Files

  7. #7
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Macro compare cells and paste to columns

    Im a little confussd of what you are wanting the results to be? Are you wanting to call the macro from the form?

  8. #8
    Forum Contributor
    Join Date
    04-03-2012
    Location
    Washington State
    MS-Off Ver
    Excel 365
    Posts
    340

    Re: Macro compare cells and paste to columns

    Ultimately, I would like to have the Part Number column first, which is the one I want to use for the compare method. So I would have it like this:

    Column A Column B Column C Column D Column E
    Part Number Date/Time Job Operator Part IN/OUT

  9. #9
    Forum Contributor
    Join Date
    04-03-2012
    Location
    Washington State
    MS-Off Ver
    Excel 365
    Posts
    340

    Re: Macro compare cells and paste to columns

    I am calling the macro on workbook open, which is fine for now. I just need to add more columns with the Part Number column being the one to compare and then paste along side like it does with what is there now.

  10. #10
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Macro compare cells and paste to columns

    Im stiil confused some. With the data that is showing on sheet1 can you show on sheet2 your expected results?

  11. #11
    Forum Contributor
    Join Date
    04-03-2012
    Location
    Washington State
    MS-Off Ver
    Excel 365
    Posts
    340

    Re: Macro compare cells and paste to columns

    Ooops, sorry about that. I changed it to all show on sheet1 for testing. Right now I have the 3 columns... and that works great. I need to add more columns, but the way it works now, it will overwrite the data. On Sheet1, you will see part number "CA197-01" and then you see it again a few lines down which tells me the part came back in. When the macro runs, It will then paste that entire line next to the line it matches up with.

    So the way I am wanting to use this is, a bunch of parts get scanned OUT.... I just need to find which ones got scanned back IN. I hope I am making sense.

  12. #12
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Macro compare cells and paste to columns

    Can you upload another workbook that has the other columns that you want to add, and not call the macro from the thisworkbook.open event?

  13. #13
    Forum Contributor
    Join Date
    04-03-2012
    Location
    Washington State
    MS-Off Ver
    Excel 365
    Posts
    340

    Re: Macro compare cells and paste to columns

    Mike, Here is the workbook showing what I need. The userform will be filling in this data. So from the worksheet, all 3 part numbers went "OUT" and all 3 came back "IN", so there will be a part number match for all three and the data can copy to sheet2 when the macro runs. Your code works well, I just want to understand how it works so I can modify it with your help.
    Attached Files Attached Files

  14. #14
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Macro compare cells and paste to columns

    This what you want?

    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    04-03-2012
    Location
    Washington State
    MS-Off Ver
    Excel 365
    Posts
    340

    Re: Macro compare cells and paste to columns

    This is very very close... can I have it copy all columns for each match of the part number? I need that since the operator taking them them IN will be different from the one taking them OUT. I see this is copying the date and IN only

  16. #16
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Macro compare cells and paste to columns

    You mean like this. Just replace the for loop in the currunt code with the one below

    Please Login or Register  to view this content.

  17. #17
    Forum Contributor
    Join Date
    04-03-2012
    Location
    Washington State
    MS-Off Ver
    Excel 365
    Posts
    340

    Re: Macro compare cells and paste to columns

    Thanks Mike .... I think this will work perfectly. I appreciate your time and help.

+ 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