how do I increment letters of the alphabet for a database
For something quick-n-dirty, how about a function that Ranks your string,
adds 1, and then unranks it?
For example, if you have "AAAAA" in A1, put this in A2.
=NextSequence(A1)
At some future time, perhaps you can Copy - Paste Special Values.
Function NextSequence(s) As String
Dim UB As Long
Dim k As Long
Dim n As Long
Dim j As Long
Dim v() As Variant
Const b As Long = 26 'Base 26
UB = Len(s)
k = 1
ReDim v(1 To UB)
For j = 1 To UB
v(j) = Asc(Mid$(s, j, 1)) - 65
Next j
For j = UB To 1 Step -1
n = n + (v(j) Mod b) * k
k = k * b
Next j
n = n + 1
For j = UB To 1 Step -1
v(j) = Chr((n Mod b) + 65)
n = n \ b
Next
NextSequence = Join(v, vbNullString)
End Function
--
HTH :)
Dana DeLouis
Windows XP & Excel 2007
"gretchen" wrote in message
...
Howdy,
I use a database that contains an id field that is a 5 letter "code". So
the first item in the database is AAAAA, the second is AAAAB, the third is
AAAAC and so on until item 26 is AAAAZ. Item 27 is AAABA, then 28 is
AAABB,
then 29 AAABC and on and on.
Is there a way for excel to increment all the letters up to ZZZZZ in
seperate cells?
Thanks!
|