Function Azalea_UPC_A_checkDigit(ByVal UPCnumber As String) As String ' UPCTools 16may12 jwhiting ' Copyright 2012 Azalea Software, Inc. All rights reserved. www.azaleabarcodes.com ' Calculating the UPC version A checkdigit in Excel ' Your input, UPCnumber, is a string consisting of an 11-, 12-, or 14-digit number. Dim checkDigitSubtotal As Integer ' a check digit throwaway ' Possible valid input includes 11-digits (no check digit), 12-digits (with check digit), or 14-digits (GTIN). Select Case Len(UPCnumber) Case 11 ' We're going to do the UPC check digit calculation because the input doesn't have it. Case 12 ' Let's strip your check digit and calculate ours from scratch. (Nothing personal.) UPCnumber = Left(UPCnumber, 11) Case 14 ' GTIN input, but we're going to strip the leading 2 and the last characters to extract the 11-digit input without check digit. UPCnumber = Mid(UPCnumber, 3, 11) Case Else ' Your error handling goes here... End Select ' Now we need to do the UPC A check digit calculation. ' Add up the numbers in the odd positions left to right. Multiple the result by 3. ' Add up the numbers in the even positions. Now add the first subtotal to the second. ' The UPC barcode check digit is the single digit number makes the total a multiple of 10. checkDigitSubtotal = (Val(Left(UPCnumber, 1))) + (Val(Mid(UPCnumber, 3, 1))) + (Val(Mid(UPCnumber, 5, 1))) + (Val(Mid(UPCnumber, 7, 1))) + (Val(Mid(UPCnumber, 9, 1))) + (Val(Right(UPCnumber, 1))) checkDigitSubtotal = (3 * checkDigitSubtotal) + (Val(Mid(UPCnumber, 2, 1))) + (Val(Mid(UPCnumber, 4, 1))) + (Val(Mid(UPCnumber, 6, 1))) + (Val(Mid(UPCnumber, 8, 1))) + (Val(Mid(UPCnumber, 10, 1))) Azalea_UPC_A_checkDigit = Right(Str(300 - checkDigitSubtotal), 1) ' Excel: B1=Azalea_UPC_A_checkDigit(A1) ' Or put another way, yourContainer.text=Azalea_UPC_A_checkDigit(yourInputString) End Function