Excel VBA Loop on columns

calendar_today Asked Dec 21, 2012
thumb_up 13 upvotes
history Updated April 16, 2026

Question posted 2012 · +5 upvotes

when we are going to do a loop in the rows, we can use code like the following:

i = 1
Do
   Range("E" & i & ":D" & i).Select
   i = i + 1
Loop Until i > 10

but what if we want to do a loop on a column?

Can we use the same method as above?

while the columns in Excel is a complex such as A, B, C, …, Y, Z, AA, AB, AC, …, etc. problems will arise between loop from the “Z” to the “AA”.

how we do looping alphabet column from “A” to “Z” and then continued into “AA”, “AB” and so on

is there anything that can help?

Accepted answer +13 upvotes

Yes, let’s use Select as an example

sample code: Columns("A").select

How to loop through Columns:

Method 1: (You can use index to replace the Excel Address)

For i = 1 to 100
    Columns(i).Select
next i

Method 2: (Using the address)

For i = 1 To 100
 Columns(Columns(i).Address).Select
Next i

EDIT: Strip the Column for OP

columnString = Replace(Split(Columns(27).Address, ":")(0), "$", "")

e.g. you want to get the 27th Column –> AA, you can get it this way

3 code variants in this answer

  • Variant 1 — 3 lines, starts with For i = 1 to 100
  • Variant 2 — 3 lines, starts with For i = 1 To 100
  • Variant 3 — 1 lines, starts with columnString = Replace(Split(Columns(27).Address, ":")(0), …

Top excel-vba Q&A (6)

+13 upvotes ranks this answer #39 out of 136 excel-vba solutions on this site .