It would have been nice to have a before and after example of a GTIN, but with what you provided and searching the web, I cobbled a function together.
In this function, the GTIN must be a string.
The function:
Code:
Public Function CalcGTIN(pGTIN As String) As String
'http://www.gs1sy.org/GS1System/id_keys/CheckDigit.htm
'the number to multiply by
Const N As String = "131313131313"
Const NumOfDigits As Integer = 12
Dim i As Integer 'counter
Dim ChkDigit As Long '
Dim txtBase As String '
Dim x As Long
'set default return value
CalcGTIN = "00000000000000"
txtBase = Trim(pGTIN)
If Len(txtBase) = NumOfDigits Then
For i = 1 To NumOfDigits
x = x + (Mid(txtBase, i, 1) * Mid(N, i, 1))
Next
' next bigger number and subtract ChkNum
ChkDigit = (x + (10 - (x Mod 10))) - x
'return
CalcGTIN = "1" & txtBase & ChkDigit
End If
End Function
Call it using:
Code:
Sub TestGTIN()
Dim sWithCheckdigit As String
Dim TradingProcessNum As String
TradingProcessNum = "629104150021"
sWithCheckdigit = CalcGTIN(TradingProcessNum)
'this should be one line
MsgBox "Original = " & TradingprocessNum & " - " & Len(TradingProcessNum) & " characters " & vbNewLine & vbNewLine & "GTIN = " & sWithCheckdigit & " - " & Len(sWithCheckdigit) & " characters "
End Sub