Thread: I'm a newbie
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
TT[_3_] TT[_3_] is offline
external usenet poster
 
Posts: 5
Default I'm a newbie

So you have a dialog with probably a textbox and a button on it. Here is
some code you could put in the button's click event:

Private Sub CommandButton1_Click()
Dim i As Integer, last As Integer

If IsNumeric(TextBox1.Value) Then
last = TextBox1.Value
If last < 1 Or last 26 Then
MsgBox "Enter a number between 1 and 26", vbExclamation
GoTo ExitSub
End If

For i = 1 To last
Cells(1, i) = Chr(64 + i)
Next i
Else
MsgBox "Enter a number between 1 and 26", vbExclamation
End If

ExitSub:
Unload Me
End Sub

Chr(65) yields an "A", Chr(64+26) yields the "Z". Add another 32 to get
the lowercase equivalents.

With kind regards,
Ton Teuns

*** Sent via Developersdex http://www.developersdex.com ***