简体   繁体   中英

Excel - Macro to compare /match multiple cells in a row between two sheets, and copy the entire row to the second sheet

i'm looking for macro to match multiple cells in a row between two sheets, and copy the entire matched row from the first sheet to place beside the matched row from the second sheet.

Below are excerpts of my excel worksheet:

worksheet A:

    E       F   H          J

2878 3/1/2011 Cash 1/3/2011_BSJ 636

worksheet B:

   A      C        E   F

50 1-Mar-11 DEP_CASH 636 TRAX_BRH_BSJ

For example if F2878 (row no. 2878, column F), E2878, J2878, H2878 of worksheet A = C50, A50, E50, F50 of worksheet B then copy whole 2878 row of worksheet A to I50 of worksheet B. Then strike through the 2878 row from worksheet A to indicate work done of a row. Note that some of the content might not exactly the same, like F2878 contains "Cash" & C50 contain "CASH" out of "DEP_CASH" which are considered matched. I need to match some 3000+ row. Please help...

The problem is that the lookup-functions do only consider a single key column. So what I did on a similar problem is to add a single key column using some formula to concatenate the key parts with some special character, and then use a lookup-formula. As you have to create matching keys on both sides, you have a chance in the formulas building them to unify the texts. Eg use uppercase to make sure they are spelled the same. Or just cut the word CASH out of a column...

Takes some trial and error... but as you can see the keys created, you can adopt your formula until it delivers the expected results.

(Depending on how complicated your matching logic is, something capable of handling regular expressions might help, eg Ruby, which is great at "remote controlling" Excel.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM