Formula for MOD 10 Weight 2 Algorithm

inosent

Board Regular
Joined
Mar 19, 2007
Messages
131
I am looking for an xl formula to calculate the check digit for a MERS MIN. They tell me it is a MOD 10 Weight 2 Algorithm.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
I searched for check digit algorithm on google, and got this routine. It should do what you are asking for with a bit of thought. A formula would be more difficult.... but the basic principle of a mod 10 check is to multiply alternate digits by 2 or 1 and add all the results. Then use divide by 10 and use the remainder as your check digit.
Code:
<code class="vb keyword">Function</code> <code class="vb plain">checkdigit(idWithoutCheckDigit)</code>
 
<code class="vb plain">ucIdWithoutCheckdigit = UCase(idWithoutCheckDigit)</code>
<code class="vb plain">total = 0</code>
<code class="vb keyword">For</code> <code class="vb plain">i = Len(ucIdWithoutCheckdigit) </code><code class="vb keyword">To</code> <code class="vb plain">1 </code><code class="vb keyword">Step</code> <code class="vb plain">\-2</code>
<code class="vb plain">digit = Asc(Mid(ucIdWithoutCheckdigit, i, 1)) - 48</code>
<code class="vb plain">total = total + (2 * digit) - Int(digit / 5) * 9</code>
<code class="vb keyword">If</code> <code class="vb plain">(i > 1) </code><code class="vb keyword">Then</code>
<code class="vb plain">digit = Asc(Mid(ucIdWithoutCheckdigit, i - 1, 1)) - 48</code>
<code class="vb plain">total = total + digit</code>
<code class="vb keyword">End</code> <code class="vb keyword">If</code>
<code class="vb keyword">Next</code> <code class="vb plain">i</code>
<code class="vb plain">total = Abs(total) + 10</code>
<code class="vb plain">checkdigit = (10 - (total </code><code class="vb keyword">Mod</code> <code class="vb plain">10)) </code><code class="vb keyword">Mod</code> <code class="vb plain">10</code>
 
<code class="vb keyword">End</code> <code class="vb keyword">Function</code>
 
Last edited:
Upvote 0
Hi,

If you confirm the algorithm then I'm sure this will be quite doable using worksheet formulas alone as well.

Regards
 
Upvote 0

Forum statistics

Threads
1,224,747
Messages
6,180,716
Members
452,995
Latest member
isldboy

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