Using EAN barcodes in Excel

VB code for generating the check digit for EAN8 and EAN13 barcodes
This code generates a checksum needed for EAN-8 and EAN-13 borcodes. The input (Base) is either a 7 or a 12 digit string. The number generated by the EAN function should be added to the end of the Base to make a valid barcode number.

Function EAN(Base As Variant) As Integer
    Z = 0: Odd = True
    For x = Len(Base) To 1 Step -1
        If Odd Then
            Z = Z + Mid(Base, x, 1) * 3
            Odd = False
            Z = Z + Mid(Base, x, 1)
            Odd = True
        End If
    EAN = 10 - Z Mod 10
    If EAN = 10 Then EAN = 0
End Function

Leave a Reply

Your email address will not be published. Required fields are marked *