Excel VBA Loop on columns

前端 未结 4 1594
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-14 03:12

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
Loo         


        
4条回答
  •  爱一瞬间的悲伤
    2020-12-14 03:47

    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

提交回复
热议问题