Replace last number using provided matrix

richmcgill

Board Regular
Joined
Feb 4, 2019
Messages
86
Office Version
  1. 2016
Platform
  1. Windows
I need to apply the matrix below to a group of numbers
The matrix replaces the last number of the whole number with the specified character.
A negative number
-2505.25 would be 2505.2N
A positive number
31066.83 would be 31066.8C

Make sense?

Final Digit of NumberPositive Replacement CharacterNegative Replacement Character
1AJ
2BK
3CL
4DM
5EN
6FO
7GP
8HQ
9IR
0{}
 
Quick question.
If I wanted to use the same (the new one you resorted) matrix and apply replacing the last digit of the Date number in the spreadsheet keeping it three digits what would that look like?
001 would be 00A
-012 would be 01K
-005 would be 00N

Loan NumberCodeReasonDate
1234565AAAA001
2345676BBBB-012
3456788CCCC008
4567897EEEE-005
You can try this for the 3 digit problem:
Book1
FGH
100100A
2-01201K
300800H
4-00500N
Sheet4
Cell Formulas
RangeFormula
H1:H4H1=LEFT(TEXT(ABS(F1),"000"),LEN(TEXT(ABS(F1),"000"))-1)&LOOKUP(RIGHT(F1,1)*1,$N$2:$N$11,IF((F1)*1>=0,$O$2:$O$11,$P$2:$P$11))
 
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
And I have this working for the original problem, though I rearranged the matrix slightly from your original orientation. I put line 0 above instead of at the end because LOOKUP needs to be in ascending order. Anyway, for this version to work, the balance values should be converted to text to properly recognize the trailing 0. Maybe @felixstraube can adjust his formula to account for the tens place 0 too, but for the moment, this should work if you convert your balances to text.
Book1
IJKLMNOP
1-50756.0250756.0KFinal Digit of NumberPositive Replacement CharacterNegative Replacement Character
227861.4827861.4H0{}
340399.5940399.5I1AJ
433034.4833034.4H2BK
575701.8675701.8F3CL
655527.8055527.8{4DM
7-91358.8091358.8}5EN
86383.606383.6{6FO
9-56943.3856943.3Q7GP
10-97315.6997315.6R8HQ
11-10585.6710585.6P9IR
1234849.2534849.2E
1315970.5115970.5A
144856.324856.3B
15-78592.5778592.5P
16-52665.7752665.7P
17-15140.8215140.8K
1893981.0193981.0A
19-55953.5755953.5P
2064066.6864066.6H
2123742.5423742.5D
2261665.6461665.6D
23-39963.0939963.0R
24-47585.3547585.3N
254928.594928.5I
26-62347.2362347.2L
2797990.5897990.5H
28-35061.0635061.0O
2997556.4197556.4A
3021993.7021993.7{
Sheet4
Cell Formulas
RangeFormula
I1:I30I1=TEXT(A1:A30,"0.00")
J1:J30J1=LEFT(TEXT(ABS(I1),"0.00"),LEN(TEXT(ABS(I1),"0.00"))-1)&LOOKUP(RIGHT(I1,1)*1,$N$2:$N$11,IF((I1)*1>=0,$O$2:$O$11,$P$2:$P$11))
Dynamic array formulas.
 
Upvote 0
I ran into a problem with the first formula, it does not recognize when there is a zero at the end of the number and the negative it added the special character at the end of the negative number not replacing the last digit.

The new option works much better and so far I cannot find any flaws.

Thank you so much for your help!
You are welcome. Thanks for the feedback!
 
Upvote 0
Are you sure? What happens with values of .0#?
Book1
ABCD
1-50756.0250756.02K50756Q
Sheet4
Cell Formulas
RangeFormula
B1B1=LEFT(ABS(A1),LEN(A1)-1)&LOOKUP(RIGHT(A1,1)*1,$N$2:$N$11,IF(A1>=0,$O$2:$O$11,$P$2:$P$11))
D1D1=TRUNC(ABS(A1), 1)&INDEX($Q$2:$R$11, 1+MOD(ABS(A1)*100, 10), 1+(A1<0))


See col D for felix's formula. It got the last digit right for the character, but then it removed the .0 before the last digit. Is that the desired outcome? Should it be 50756.0Q?
You are right, for the .0 numbers the formula didn't work properly.
Here is the corrected formula:

Excel Formula:
=TEXT(TRUNC(ABS(E2), 1), "0.0")&INDEX($J$2:$K$11, 1+MOD(ABS(E2)*100, 10), 1+(E2<0))
 
Upvote 1

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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