Forum Discussion
HSalles
Dec 23, 2022Copper Contributor
How to create a alphanumeric sequence on vba
Hi, I need to create a code that are composed by 2 digits and I want to use all the numbers (0-9) and letters (A-Z). Could some help me to create the vba code to do this please? Ex: after th...
- Dec 27, 2022
New version:
Function nextUDI(prevUDI As String) As String 'Gera UDI com base no número anterior Dim prefixo As String Dim n As Long Dim prevVal As Long Const strAlphabet = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ" n = Len(prevUDI) prevVal = 34 * (InStr(strAlphabet, Mid(prevUDI, n - 1, 1)) - 1) + InStr(strAlphabet, Right(prevUDI, 1)) - 1 prefixo = Left(prevUDI, n - 2) nextUDI = prefixo & fBase34(prevVal + 1) End Function
HansVogelaar
Dec 23, 2022MVP
Function nextUDI(prevUDI As String) As String
'Gera UDI com base no número anterior
Dim prefixo As String
Dim prevVal As Long
prevVal = Application.Decimal(Right(prevUDI, 2), 34)
prefixo = Left(prevUDI, Len(prevUDI) - 2)
nextUDI = prefixo & fBase34(prevVal + 1)
End Function
HSalles
Dec 26, 2022Copper Contributor
HansVogelaar
I was using the vba code that you suggested but when the code comes to 3J it is jumpping to 3L, 3N to 3Q and 3Y or 3Z to #value. Could you help me please?
I was using the vba code that you suggested but when the code comes to 3J it is jumpping to 3L, 3N to 3Q and 3Y or 3Z to #value. Could you help me please?
- HansVogelaarDec 27, 2022MVP
New version:
Function nextUDI(prevUDI As String) As String 'Gera UDI com base no número anterior Dim prefixo As String Dim n As Long Dim prevVal As Long Const strAlphabet = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ" n = Len(prevUDI) prevVal = 34 * (InStr(strAlphabet, Mid(prevUDI, n - 1, 1)) - 1) + InStr(strAlphabet, Right(prevUDI, 1)) - 1 prefixo = Left(prevUDI, n - 2) nextUDI = prefixo & fBase34(prevVal + 1) End Function
- HSallesDec 27, 2022Copper ContributorThank you HansVogelaar, it works perfectly now