Going through all possibilities from 2 lists ... How to Do?

krazykaj

Board Regular
Joined
Jul 20, 2005
Messages
143
Hello,

Here is another question (i seem to have so many :) )

Say i have this in excel:

List 1
Cell A1 = a
Cell A2 = b
Cell A3 = c

List 2
Cell B1 = 1
Cell B2 = 2
Cell B3 = 3

And then have excel, say on a commandbutton_click, run through a code, using all possibilities made by mixing the two columns together for logical tests:

So I'd like something along these lines to happen.
The generic code being:

If whatever_1stCell = varFromList1 AND whatever_2ndCell = varFromList2 then
call Do_Something
End If


And basically put that generic code into some sort of loop, so that each time it runs, the varFromList1 and the varFromList2 will change eventually represent all possibilities of the two lists. i.e. I'd like this to happen:

First loop, the code will be:
If whatever_1stCell = a AND whatever_2ndCell = 1 then
call Do_Something
End If


Second loop, the code will be:
If whatever_1stCell = a AND whatever_2ndCell = 2 then
call Do_Something
End If


Third loop, the code will be:
If whatever_1stCell = a AND whatever_2ndCell = 3 then
call Do_Something
End If


Fourth loop, the code will be:
If whatever_1stCell = b AND whatever_2ndCell = 1 then
call Do_Something
End If


Fifth loop, the code will be:
If whatever_1stCell = b AND whatever_2ndCell = 2 then
call Do_Something
End If


. . . And so on, untill the last run through the loop, where the code should be:

If whatever_1stCell = c AND whatever_2ndCell = 3 then
call Do_Something
End If

So you can see i'm trying to have it so that two variable will test all possibilities of the two lists mixed together.
i.e.
a and 1
a and 2
a and 3
b and 1
b and 2
b and 3
c and 1
c and 2
c and 3

How could i go about doing this???
Any help would be greatly appreciated :biggrin:

Hope that all made sense :(

Thankyou for your time,
Cheers
kJ
 
Thanks :)

I'll have a go . . .
I just thouht there may be a way to do it using functions again.
I've never used the advanced filter much, so it never crossed my mind to use it :)

Cheers and thankyou once more.
KJ
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,214,833
Messages
6,121,861
Members
449,052
Latest member
Fuddy_Duddy

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