Search on multiple criteria using excel vba

Kriskros07

New Member
Joined
Sep 1, 2011
Messages
11
Hi, I am in dire need of some assistance. I have scoured the existing posts but cant quite find the right post to twig with me what i need to do.

I am trying to write a macro which will search on 2 pieces of data taken from e.g. Row1, i.e. cells A1 and B1 and match those to 2 pieces of data (found together) in another part of the spreadsheet e.g. these might be in cells N7 and O7. I want the code to return the position of the matched data (presumably using Match) - so this would be 7 if it matched the data with cells N7 and O7(it could be matched anywhere in these columns of course). A seperate issue - but just to explain why i am trying to do this - I will subsequently use this positioning to compare the remaining columns of data (e.g. compare in this instance A1:M1 against N7:Z7).

A Single criteria is easy enough:
where a is the value found in cell A1
relpos = Application.Match(a, Range("N:N"), 0) 'single criteria

however, i need to add in cells B1 to the reference argument and Range O:O to the lookup array.

I believe i need to use the Evaluate function also to do this in VBA. And Index maybe??

Any help will be very much appreciated!



Kind Regards,
Chris
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Just thinking out aloud - is it an option to insert a column at C and concatenate A and B, then insert a column at P and concatenate N and O? Then you can match between C and P with single criteria.
 
Upvote 0
Second that suggestion;

Whether in code (in which case you should create your own internal data structure of concatenated search parameters and search sets) or by, as suggested, concatenating the search parameter and search set array.
 
Upvote 0
I cant insert a column as the purpose of the exercise is to compare baseline and actual results side by side. However, i can try to create a concatenated array and look for the concat reference variables within this.

Thanks for your suggestions anyway much appreciated!
 
Upvote 0
If you are unable to insert columns and compare, then the other way is to use CSE formula as suggested in the other VBAExpress message board.

Ordinary formulas perform one-dimensional look ups, CSE enables inclusion of arrays as parameters in excel formula and perform 2-dimensional look ups.
 
Upvote 0

Forum statistics

Threads
1,224,551
Messages
6,179,480
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top