Code 39 barcode checkdigit calculation

Code 39 Barcode Check Digit

Code 39 barcodes sometimes use an optional mod 43 check digit. This calculated mod 43 checksum is based on the value associated with each of the Code 39 characters. The character values in the center column of this table of the Code 39 character set are added together and divided by 43. The check digit is the character associated with the remainder.

For example, the check digit for JAZZ is D.
  J=19 A=10 Z=35 Z=35
  19 + 10 + 35 + 35 = 99
  99 / 43 = 2, remainder 13
The character with the value of 13 is D. Therefore the barcode with the check digit is JAZZD

Code 39 mod 43 check digit
*JAZZD*

The check digit is calculated in Visual Basic/VBA like this:

Option Explicit
Public Function AzaleaSoftware_Code39withCheckDigit(ByVal Code39 As String) As String
' C39Tools 31dec06 jwhiting
' Copyright 2006 Azalea Software, Inc. All rights reserved. www.azalea.com
' Code 39 barcodes sometimes, though rarely, used with an optional mod 43 check digit.
  ' The input, Code39, is a string consisting of the 44-character version
  ' of Code 39 without the start and stop bars (*).
  ' AzaleaSoftware_Code39withCheckDigit is the original input plus the mod 43 check digit
  ' character, and the start & stop bars.
  Dim charSet As String ' mod 43 lookup table
  Dim i As Integer ' loop counter
  Dim subtotal As Integer ' check digit subtotal
  charSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%"
  For i = 1 To Len(Code39)
    subtotal = InStr(charSet, Mid(Code39, i, 1)) - 1 + subtotal
  Next i
  ' concatenate the original string, Code39, and the check digit character
  AzaleaSoftware_Code39withCheckDigit = "*" + Code39 & Mid(charSet, (subtotal Mod 43 + 1), 1) + "*"
  ' The output, AzaleaSoftware_Code39withCheckDigit, is formatted using one of Azalea Software's Code 39 fonts.
  ' For example, B1=AzaleaSoftware_Code39withCheckDigit(A1)
  ' Or put another way, yourContainer.text=AzaleaSoftware_Code39withCheckDigit(yourInputString)
End Function