![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have a field that needs to auto increment each time a new entry is made. It is a text field that needs to increment in a similar way to Excel columns ie: A, B, C... continuing like this ...X, Y, Z, AA, AB, AC. etc... The maximum it needs to go to is ZZZ How do I do this in VBA? Convert each letter combination to a number, add one and then convert it back to text? Or is there a better way (built in function)? Thanks Paul |
#3
| |||
| |||
|
|
I have a field that needs to auto increment each time a new entry is made. It is a text field that needs to increment in a similar way to Excel columns ie: A, B, C... continuing like this ...X, Y, Z, AA, AB, AC. etc... The maximum it needs to go to is ZZZ How do I do this in VBA? Convert each letter combination to a number, add one and then convert it back to text? Or is there a better way (built in function)? |
#4
| |||
| |||
|
|
Paul H wrote: | I have a field that needs to auto increment each time a new entry is | made. It is a text field that needs to increment in a similar way to | Excel columns ie: | | A, B, C... | | continuing like this | | ...X, Y, Z, AA, AB, AC. etc... | | The maximum it needs to go to is ZZZ | | How do I do this in VBA? Convert each letter combination to a number, | add one and then convert it back to text? Or is there a better way | (built in function)? Public Function GetNumberFromABC(arg As String) As Long Dim a() As Byte Dim i As Long, k As Long, x As Long If arg Like "*![A-Z]*" Then GetNumberFromABC = 0 Else a = StrConv(UCase(arg), vbFromUnicode) k = UBound(a) For i = k To LBound(a) Step -1 x = x + (a(i) - 64) * 26 ^ (k - i) Next GetNumberFromABC = x End If End Function |
#5
| |||
| |||
|
|
Paul H wrote: | I have a field that needs to auto increment each time a new entry is | made. It is a text field that needs to increment in a similar way to | Excel columns ie: | | A, B, C... | | continuing like this | | ...X, Y, Z, AA, AB, AC. etc... | | The maximum it needs to go to is ZZZ | | How do I do this in VBA? Convert each letter combination to a number, | add one and then convert it back to text? Or is there a better way | (built in function)? Public Function GetNumberFromABC(arg As String) As Long Dim a() As Byte Dim i As Long, k As Long, x As Long If arg Like "*![A-Z]*" Then GetNumberFromABC = 0 Else a = StrConv(UCase(arg), vbFromUnicode) k = UBound(a) For i = k To LBound(a) Step -1 x = x + (a(i) - 64) * 26 ^ (k - i) Next GetNumberFromABC = x End If End Function |
#6
| |||
| |||
|
|
I have a field that needs to auto increment each time a new entry is made. It is a text field that needs to increment in a similar way to Excel columns ie: A, B, C... continuing like this ...X, Y, Z, AA, AB, AC. etc... The maximum it needs to go to is ZZZ How do I do this in VBA? Convert each letter combination to a number, add one and then convert it back to text? Or is there a better way (built in function)? Thanks Paul |
#7
| |||
| |||
|
|
I have a field that needs to auto increment each time a new entry is made. It is a text field that needs to increment in a similar way to Excel columns ie: A, B, C... continuing like this ...X, Y, Z, AA, AB, AC. etc... The maximum it needs to go to is ZZZ How do I do this in VBA? Convert each letter combination to a number, add one and then convert it back to text? Or is there a better way (built in function)? Thanks Paul |
#8
| |||
| |||
|
#9
| |||
| |||
|
|
Thank you every one for your answers. I have a few approaches to try out. Cheers, Paul |
![]() |
| Thread Tools | |
| Display Modes | |
| |