Loop from a to z

  • Thread starter Thread starter Madiya
  • Start date Start date
M

Madiya

I need to loop from a to z.
say
for i=a to z
......
next

How can I do it?

Regards,
Madiya
 
one way is something like this:

Sub test()
Dim i As Integer
For i = Asc("a") To Asc("z")
Debug.Print Chr(i)
Next i
End Sub
 
I need to loop from a to z.
say
for i=a to z
.....
next

How can I do it?

Here is one way to do it directly as you wrote it...

Enum Letters
a = 97: b: c: d: e: f: g: h: i: j: k: l: m
n = 110: o: p: q: r: s: t: u: v: w: x: y: z
End Enum

Sub test()
Dim X As Variant
For X = a To z
Debug.Print Chr(X)
Next
End Sub

Note that the Enum can be one single line long, like this...

Enum Letters
a = 97: b: c: d: e: f: g: h: i: j: k: l: m: n: o: p: q: r: s: t: u: v: w:
x: y: z
End Enum

but I didn't do it because I suspect the line would wrap in most
newsreaders. If it did, and you copied it that way, the first letter on the
wrapped line would be taken as a Line Label by VB; so, I figured it was
better to break it up for clarity during copying... make it into one line
after you place it into your code.

Note... while I used lower case letters in the Enum and in the For-Next
loop, the casing it not significant... upper case letters work exactly the
same as lower case within the code... the output, however, will still be
lower case because the Enum starts its assignment at 97 (the ASCII code for
lower case 'a').

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top