Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Barcode increment with letters and numbers

Status
Not open for further replies.

hstacco

Technical User
Jun 19, 2015
4
0
0
US
I am trying to increment a barcode with values A-Z...0-9 then back to A.
Values like:
AFWK9, AFWL9, AZFL9
Would increment to:
AFWLA, AFXMA, A0FMA

I am trying to use VBA to accomplish and was able to find some code which got me to the place below however my problem is I can't figure out how to handle incrementing the Third, Second and Fourth values and how to handle when the Fourth value is a 9. I've included if statements following true to below If SFourthLetter = 9 but it's not working. If someone can get me on the right track with the Fourth letter and/or the Third letter I can figure out the rest myself. I'm a little green at VBA so please bear with me. Any help you give would be much appreciated. Thank you- Heather

Function IncrementAlpha(strIn As String) As String
'Pass this function your letter string
'Example myNewString = IncrementAlpha("ab")
'will return "ac"

Dim sAlphaBet As String
Dim sFirstLetter As String
Dim sSecondLetter As String
Dim sThirdLetter As String
Dim sFourthLetter As String
Dim sFifthLetter As String
Dim X As Variant
Dim I As Long
sFirstLetter = Left(strIn, 1)
sSecondLetter = Mid(strIn, 2, 1)
sThirdLetter = Mid(strIn, 3, 1)
sFourthLetter = Mid(strIn, 4, 1)
sFifthLetter = Mid(strIn, 5, 1)
sAlphaBet = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,0,1,2,3,4,5,6,7,8,9"
X = Split(sAlphaBet, ",")



If sFifthLetter = "9" Then
'loop to get next first letter
For I = I To UBound(X) - 1
If X(I) = sFourthLetter Then
sFourthLetter = X(I + 1)
sFifthLetter = "A"
sThirdLetter = sThirdLetter
sSecondLetter = sSecondLetter
sFirstLetter = sFirstLetter
Exit For
End If
Next I

Else
'loop to get the next letter
For I = 0 To UBound(X) - 1
If X(I) = sFifthLetter Then
sFifthLetter = X(I + 1)
sFourthLetter = sFourthLetter
sThirdLetter = sThirdLetter
sSecondLetter = sSecondLetter
sFirstLetter = sFirstLetter
Exit For
End If

Next I
End If

IncrementAlpha = sFirstLetter & sSecondLetter & sThirdLetter & sFourthLetter & sFifthLetter
End Function


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top