Scoring a number based on rules

JonathanWootton

New Member
Joined
May 25, 2011
Messages
4
Hi all,

I am struggling with an excel task, that i suspect could be simple.

I have a column of numbers: eg

7763
7777
8822
1234

And i need to score the numbers based on some simple rules, being
if second number +1 of first number add 1, and second number -1 of first number add 1, if second number = first number +2 and so one.

so:

7763 would score 3
7777 would score 6
8822 would score 4
1234 would score 3

How can i do this easily (I am guessing VB might help, but struggling to get my head into it working)

Any pointers appreciated
Regards
Jonathan
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hi Jonathan, welcome to the board.

I don't fully understand how your logic works.

For 7763, are you saying it scores 3 because
a) 1st digit = 2nd digit - 2 points
b) 2nd digit is 1 more than 3rd digit - 1 point
c) 3rd digit is not within 1 point of 4th digit, therefore 0 points, TOTAL 3 POINTS ?
 
Upvote 0
Hi Gerald,

Yes thats what i was trying to get at, sorry my explanation probably wasnt great.

I think I need to use Length of number and run through iteratively scoring, but I am not sure.
 
Upvote 0
This isn't very elegant, but it does it for the first pair of digits.

You should be able to adapt this for the other two pairs.
Code:
=(LEFT(A1,1)=MID(A1,2,1))+AND((LEFT(A1,1)+0)>MID(A1,2,1)-1,
(LEFT(A1,1)+0)<MID(A1,2,1)+1)

It feels like there should be a neater formula solution than this, but I can't think of it at the moment :-)
 
Upvote 0
An array formula ( entered using Ctrl-Shift-Enter, instead of Enter ) of:

=SUM(IF(ABS(MID(A1,ROW($2:$4),1)-MID(A1,ROW($A$1:$A$3),1))=0,2,0))+SUM(IF(ABS(MID(A1,ROW($2:$4),1)-MID(A1,ROW($A$1:$A$3),1))=1,1,0))

should do it.
 
Upvote 0
Glenn,

Can you tell me why this doesn't return a 1 for 7763?

=IF((MID(A1,3,1))=(MID(A1,2,1)+1),1,IF((MID(A1,3,1))=(MID(A1,2,1)-1),1,IF((MID(A1,3,1))=(MID(A1,2,1)),2,0))))


And Glenn's formula does the trick!!
 
Upvote 0
I think I might have just answered my own question:


I added the following changes:

=IF((--MID(A1,3,1))=(--MID(A1,2,1)+1),1,IF((--MID(A1,3,1))=(--MID(A1,2,1)-1),1,IF((--MID(A1,3,1))=(--MID(A1,2,1)),2,0))))


Does this mean that the left, mid, and right functions return text, even if they are searching a number?
 
Upvote 0
Glenn,

Can you tell me why this doesn't return a 1 for 7763?

=IF((MID(A1,3,1))=(MID(A1,2,1)+1),1,IF((MID(A1,3,1))=(MID(A1,2,1)-1),1,IF((MID(A1,3,1))=(MID(A1,2,1)),2,0))))


And Glenn's formula does the trick!!
Because you are comparing text ( MID ) against numeric ( MID + x ). You need to cast your results so that you are comparing like with like. A useful operation is the double unary, --, like this:
=IF(--(MID(A1,3,1))=(MID(A1,2,1)+1),1,IF(--(MID(A1,3,1))=(MID(A1,2,1)-1),1,IF(--(MID(A1,3,1))=--(MID(A1,2,1)),2,0)))
 
Upvote 0
I think I might have just answered my own question:


I added the following changes:

=IF((--MID(A1,3,1))=(--MID(A1,2,1)+1),1,IF((--MID(A1,3,1))=(--MID(A1,2,1)-1),1,IF((--MID(A1,3,1))=(--MID(A1,2,1)),2,0))))


Does this mean that the left, mid, and right functions return text, even if they are searching a number?

Yes, they do.
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,172
Members
452,893
Latest member
denay

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