VBA Picking a conditional value.

  • Thread starter Thread starter Legacy 143009
  • Start date Start date
L

Legacy 143009

Guest
Hi guys!

I have a question. At first look it seems easy but I am a little bit confused now...

Anyway, I'll try to explan.
Let's say it's a card game;
I select 5 cards from a suit. They are in A1:A5. At least 2 of them should be the same shape in this case. I am sorting them by shape and let's say two clubs will be on top. The script that I want should solve which club to pick to B1. The rule is, the club it picked should be 1,2,3,4,5 or 6 smaller than the club remained in the 4-card group.

The difficult side for me is to set up a logic for what if I select same shaped cards more than 2. For example 3 or 4 clubs or 5?.. What kind of a script can resolve this condition.

For example:

2a.PNG


The code should pick 4 because I can go to 4 going backwards only three from 7. Antoher thing;
Let's say the clubs are 11(J) and 2, it should pick 2 because you can go to 11 only descending the number by four.
The maximum limit is six for going back. And the same cards may be more than two.

It is very difficult to tell... I know. My english is insufficient for this. If you wonder about something please don't hesitate to ask.

Thanks a lot fom this very moment!
 
Last edited by a moderator:

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Let's modify my question. The card name, card shape is not important. Forget the example above. There are also some mistakes in that example.

I have 2 values in column A (A1:A2) and they are in something like mode 14 (so the maximum limit for values can be 13 and it can't be a 0 value so it is not an exact mode 14) Anyway;

The rule is, the script should pick the one 1,2,3,4,5 or 6 smaller in compare to one other and split it to B1.

For example; If there are 2 and 11, it should pick 11 to B1 not 2. Because;
You if you pick 2 to B1, you can't reach to it by going 1,2,3,4,5 or 6 backwards from 11.
But if you pick 11 to B1, you can go to it by descend 3 from 2.

I hope it is more clear.


Thanks a lot!

PS: Extra work with this script is the values have prefixes as text values seperated with space. As I told you before, it looks like "CLUB 5" or "SPADE 12"... So the script should read the numbers after space.
 
Last edited by a moderator:
Upvote 0
OK let make it simple;
I have an idea. How about,
Code:
Sub Script()

Look If A1=01 Then Look and Find If A2=13 or A2=12 or A2=11 or A2=10 or A2=09 or A2=08
If True Pick A2 to B1, Else 
Look If A1=02 Then Look and Find If A2=01 or A2=13 or A2=12 or A2=11 or A2=10 or A2=09
If True Pick A2 to B1, Else
Look If A1=03 Then Look and Find If A2=02 or A2=01 or A2=13 or A2=12 or A2=11 or A2=10
If True Pick A2 to B1, Else 
Look If A1=04
.
.
.
.
.
Look If A1=13 Then Look and Find If A2=12 or A2=11 or A2=10 or A2=09 or A=08 or A2=07
If True Pick A2 to B1, Else
[B]Look If A2=01 Then Look[/B] [B]and Find If A1=13 or A1=12 or A1=11 or A1=10 or A1=09 or A1=08
If True Pick A1 to B1, Else
[/B]Look If A2=02 Then Look and Find If A1=01 or A1=13 or A1=12 or A1=11 or A1=10 or A1=09
If True Pick A1 to B1, Else
Look If A2=03
.
.
.
.
.
Look If A2=13 Then Look and Find If A1=12 or A1=11 or A1=10 or A1=09 or A1=08 or A1=07
If True Pick A1 to B1

End Sub()

In this example I wanted to check all the possible conditions which are meeting my needs. First it looks if the condition is met between A1 and A2 by the all possible 13 situation. After the line I marked BOLD, it checks if the condition is met between A2 and A1. In my problem all the probabilities are mentioned with these 26 condition so it ends up with the last line and there is no Else. But I am not sure how to write it in VB.

May anyone help, please?
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

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