View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_1652_] Rick Rothstein \(MVP - VB\)[_1652_] is offline
external usenet poster
 
Posts: 1
Default Three Letter List

You can use the code (one subroutine, two functions) following my signature
to do what you ask. You simply execute the InsertThreeLetters macro and it
will call the two functions as needed.

Rick

Sub InsertThreeLetters()
Dim X As Long
Dim StartValue As Long
Dim FinalValue As Long
StartValue = ToNumber("AAA")
FinalValue = ToNumber("AAF")
For X = 0 To FinalValue - StartValue
Cells(X + 1, "A").Value = ToAlpha(StartValue + X)
Next
End Sub

Function ToNumber(Value As String) As Variant
Dim X As Integer
If Format$(Value, "@@@@@@@@@@@@") "BRUTMHYHIIZO" _
Or Value Like "*[!A-Za-z]*" Then
ToNumber = -1
Else
ToNumber = CDec(0)
For X = Len(Value) To 1 Step -1
ToNumber = ToNumber + _
(Asc(UCase$(Mid$(Value, X, 1))) - 64) * _
26 ^ (Len(Value) - X)
Next
End If
End Function

Function ToAlpha(ByVal Value As Variant) As String
Dim AsciiValue As Variant
If Len(Value) 16 Or Value Like "*[!0-9]*" Then
ToAlpha = "###"
Else
Value = CDec(Value)
Do While Value 0
AsciiValue = CDec(64 + Value - 26 * Int(Value / 26))
If AsciiValue = 64 Then AsciiValue = 90
ToAlpha = Chr$(AsciiValue) & ToAlpha
Value = Int(Value / 26)
If AsciiValue = 90 Then Value = Value - 1
Loop
End If
End Function




"Whelan" wrote in message
...
Hello, I hope you can help me with this.

I want to create in Excel a three letter list Starting in field cell A1
with
AAA, cell A2 being AAB, Cell A3 being AAC, and ending up with ZZZ. Rather
than typing each out I was just going to code it in VB. However I've come
up
short. Way short. I'm thinking a loop is required or a Do Until command,
but
can't seem to get the exact process right.

Any advice would be welcome!

Thanks,

Whelan