Function Azalea_GS1_128_C(ByVal yourData As String) As String ' C128Tools 31may12 jwhiting ' Copyright 2012 Azalea Software, Inc. All rights reserved. www.azaleabarcodes.com ' Create a GS1-128 code set C barcode in Excel ' Input error checking is your responsibility. Dim fontString As String ' the output string Dim temp As String ' a temporary placeholder Dim checkDigitSubtotal As Integer ' a check digit throwaway Dim i As Integer ' the loop counter Dim chunk As String ' loop chunk ' seed the variables fontString = Chr(183) & Chr(205) ' code set C start & FNC1 checkDigitSubtotal = 207 ' code set C start (105) + FNC1 (102) checkdigit values ' checkDigitSubtotal & fontString are both OK to here ' do check digit calculation over yourData, assuming it's an even number of digits long temp = yourData For i = 1 To Len(yourData) / 2 chunk = Left$(temp, 2) checkDigitSubtotal = checkDigitSubtotal + Val(chunk) * (i + 1) Select Case Val(chunk) Case 0 fontString = fontString + Chr(206) Case 1 To 93 fontString = fontString & Chr(Val(chunk) + 32) Case Is > 93 fontString = fontString & Chr(Val(chunk) + 103) End Select temp = Right$(temp, Len(temp) - 2) Next i checkDigitSubtotal = checkDigitSubtotal Mod 103 ' Put together the final output string ' code set C start bar, the encoded string, check digit, stop bar Select Case checkDigitSubtotal Case 0 ' Mark Presley bug fix 19jan09 Azalea_GS1_128_C = fontString & Chr(206) & Chr(196) Case 1 To 93 Azalea_GS1_128_C = fontString & Chr(checkDigitSubtotal + 32) & Chr(196) Case Is > 93 Azalea_GS1_128_C = fontString & Chr(checkDigitSubtotal + 103) & Chr(196) End Select End Function