View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jake Marx[_3_] Jake Marx[_3_] is offline
external usenet poster
 
Posts: 860
Default Increment Alpha Character

Hi Dan,

Dan wrote:
I have a macro which sends data out to a .csv file. My
problem is that I need each line
of the .csv file to have a unique four digit alpha
character starting with AAAA and working all the way to
ZZZZ. I have no clue how to do this.


Probably not the most efficient way, but this method should work to generate
the strings from AAAA through ZZZZ:

Sub test()
Dim anBase26(1 To 4) As Integer

anBase26(1) = 0
anBase26(2) = 0
anBase26(3) = 0
anBase26(4) = 0

Do While anBase26(1) <= 25
Debug.Print Chr$(anBase26(1) + 65) & _
Chr$(anBase26(2) + 65) & _
Chr$(anBase26(3) + 65) & _
Chr$(anBase26(4) + 65)
If anBase26(4) < 25 Then
anBase26(4) = anBase26(4) + 1
Else
anBase26(4) = 0
If anBase26(3) < 25 Then
anBase26(3) = anBase26(3) + 1
Else
anBase26(3) = 0
If anBase26(2) < 25 Then
anBase26(2) = anBase26(2) + 1
Else
anBase26(2) = 0
anBase26(1) = anBase26(1) + 1
End If
End If
End If
Loop
End Sub


--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]