×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Barcode increment with letters and numbers

Barcode increment with letters and numbers

Barcode increment with letters and numbers

(OP)
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


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close