简体   繁体   中英

Find values in a worksheet with two criteria matches, copy them and paste them to another sheet with VBA

Here is my problem:

Sheet1 = "Interface". Sheet2 = "Data".

Column C5:C160 in "Data" contains a list of tasks. Row D4:M4 in "Data" contains a list of position types (jobs), which I have labelled with "job categories" from 1-10. The range D5:M160 contains work-hours for each task and position type.

Values in columns E and F in "Interface" are related to columns C and row 4 in "Data" through data validation.

What I want to do is create an advanced filter that can copy values from D5:M160 in "Data" and paste these in column G in "Interface", if the values in columns E and F "Interface" match the values in column C and row 4 in "Data" respectively, simultaneously.

This means that it should be a macro to copy and paste values with matching multiple criteria (two criteria) from one sheet to another.

I have tried different things, with no success. I have also tried array formulas, vlookup and sumifs with multiple criteria, but none of these seem work.

Any ideas?

I appreciate your help!

The index formula combined with match is built just for this.

Index returns a value from a specified table when you provide a row and column.

Match is used to return the row/column based on criteria.

So on the Interface sheet (assuming your data starts in Row 1) you can place the following formula in G1 and copy it down as needed.

=INDEX(Data!$D$5:$M$160,MATCH(E1,Data!$C$5:$C$160,0),MATCH(F1,Data!$D$4:$M$4,0))

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