Code 39 barcodes with check digits in Excel Azalea_Code_39_checkdigit Copyright 2009 Azalea Software, Inc. All rights reserved. www.azalea.com The macro in this spreadsheet creates Code 39 (Code 3 of 9) barcodes with the optional mod 43 check digit. Please note that this check digit is rarely used with Code 39 barcodes. Because this spreadsheet is built around a macro, you *must* enable macros for this spreadsheet to work! The .xls file is for Excel 2003 and the .xlsm is for Excel 2007. An alternative is to use a User Defined Function as an .xla (Excel 2003) or .xlam (Excel 2007). Press ALT-F11 to view the macro in the Visual Basic Editor. To add the macro to your own spreadsheet: Tools/Macro/Visual Basic Editor Insert/Module Paste in the macro code Close the Visual Basic Editor When you return to your spreadsheet, a new User Defined function is available: Azalea_Code_39_checkdigit C39Tools prints Code 39 barcodes. Available for Windows, OS X, Linux/UNIX, et al. Free sample code and free tech support. Buy online and download immediately. www.azalea.com/Code-39 Function Azalea_Code_39_checkdigit(ByVal Code39 As String) As String ' C39Tools 25mar09 jwhiting ' Copyright 2009 Azalea Software, Inc. All rights reserved. www.azalea.com ' Creating a Code 39 barcode with the optional mod 43 check digit in Excel ' Your input, Code39, is a string to be encoded as a Code 39 symbol that includes the mod 43 check digit. ' yourData must be the Code 39 character set. Input error checking is your responsibility. ' The standard Code 39 character set is: A-Z (upppercase), 0-9, $ % + - . / and the space character. Dim i As Integer ' our loop counter Dim subtotal As Integer ' the check digit subtotal Dim temp As String ' a temporary placeholder temp = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%" ' calculate the mod 43 check digit For i = 1 To Len(Code39) subtotal = InStr(temp, Mid(Code39, i, 1)) - 1 + subtotal Next i ' concatenate the original string, Code39, and the check digit character Azalea_Code_39_checkdigit = "*" + Code39 & Mid(temp, (subtotal Mod 43 + 1), 1) + "*" ' Excel: B1=Azalea_Code_39_checkdigit(A1) ' Or put another way, yourContainer.text=Azalea_Code_39_checkdigit(yourInputString) End Function