UPC bar code check digit calcuation

What is the UPC check digit?

The last digit in all UPC barcodes is a check digit.The UPC check digit is the single character in the lower right corner of a UPC version A barcode. It's based on the 11 digits preceeding it. The check digit has to match the numbers in the barcode or a barcode scanner will reject it.

You can figure out the check digit by hand but that's impractical in most situations. To do so, 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.

Calculate it in Excel instead. Download this free spreadsheet for UPC check digits.

Azalea_UPC-A-checkdigit spreadsheet

Here's the checkdigit calculation done in Visual Basic or VBA (Excel macro):

Option Explicit

Function Azalea_UPC_A_checkDigit(ByVal UPCnumber As String) As String
' 18dec08 Jerry Whiting
' Copyright 2008 Azalea Software, Inc. All rights reserved. www.azalea.com
' Your input, UPCnumber, is an 11 character string for a UPC version A barcode.
' This function calculates the check digit value for your 11-digit input.

Dim checkDigitSubtotal As Integer ' check digit throwaway

' Valid input is 11-digits (no check digit), 12-digits (with check digit), or 14-digits (GTIN).
Select Case Len(UPCnumber)
Case 11
' do check digit calculation
Case 12
' lets ignore your check digit & use ours
UPCnumber = Left(UPCnumber, 11)
Case 14
' GTIN input, strip leading 2 characters & last one too;
UPCnumber = Mid(UPCnumber, 3, 11)
Case Else
' error handling goes here
End Select

' do the check digit
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)

End Function

UPCTools includes the check digit when you use it to print UPC barcodes.