# Fill Alphabet Across Columns

• Today, I set myself the exercise to populate the first row with the 256 column names A,B,C...IV

There are several lines of the code, in BOLD and UNDERLINED which seem extraneous and a resort to brute force. Is there a better (in the sense of more elegant) way to do this?

I worked on this for some hours today, and might have posted here several times, with things that stumped me, such as errors when the subscript of an array is zero, or how to compute modulus, but I struggled and took this as far as I could on my own. I think it is working correctly now. If you un-comment the msgbox line, then you can watch it step cell by cell, which should be entertaining and instructive for other beginners.

• Re: Ineligent Algorithm

Just had a quick look...

Code
``````For c = 1 To 256
i = Int(c / 26)
j = c Mod 26
If c > 26 Then
i = IIf(j = 0, i - 1, i)
j = IIf(j = 0, 26, j)
arg = alphabetlist(i) & alphabetlist(j)``````
• Re: Ineligent Algorithm

• Re: Ineligent Algorithm

Mavyak, wow! Nice! Fast! Food for thought, thanks.

• Re: Ineligent Algorithm

If you want to brush up whole thing then

Code
``````Sub test()
Dim i As Integer
Dim a(1 To 256)
For i = 1 To 256
a(i) = Replace(Cells(1,i).Address(0, 0, xlA1), "1", "")
Next
Range("a1").Resize(,256).Value = a
End Sub``````
• Re: Ineligent Algorithm

Karebac, what has your Title Ineligent Algorithm to do with your post. In fact, what is "Ineligent" as far as I know there is no such word?

• Re: Inelegant Algorithm

I think the question itself also should be edited...
OP doesn't seem to know how to ask question properly.

• Re: Inelegant Algorithm

Quote from ByTheCringe2

Yes, but who would ever search that term and how does it relate to the question?

• Re: Inelegant Algorithm

Well the question is "is there a more elegant way of programming this", so that agrees with the title. I agree no-one will search on "inelegant", but I have just corrected the spelling - I leave it to someone with a more creative mind to put in a title with relevant keywords... ::D

• Re: Fill Alphabet Across Columns

Thanks for the great tips, and also corrections/admonitions with regard to forum rules regarding titles, which I am slowly learning. My apologies for the spelling error. I now know to ask myself how my title might best contribute to the search engine.

• Re: Inelegant Algorithm

Why a loop?

Boo!:yikes:

## Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!