Create excel ranges using column numbers in vba?

前端 未结 9 2286
误落风尘
误落风尘 2021-02-02 05:56

How is it possible to create a range in vba using the column number, rather than letter?

9条回答
  •  没有蜡笔的小新
    2021-02-02 06:21

    These answers seem strangely convoluted. Unless I'm missing something...if you want to convert numbers to letters, you can just stock them all in an array using a for loop then call on the number associated with that column letter. Like so

    For intloop = 1 To 26
        colcheck(intloop) = Chr$(64 + intloop)
        For lenloop = 1 To 26
            colcheck((intloop * 26) + lenloop) = Chr$(64 + intloop) & Chr$(64 + lenloop)
            For terloop = 1 To 26
                colcheck((intloop * 676) + (lenloop * 26) + terloop) = Chr$(64 + intloop) & Chr$(64 + lenloop) & Chr$(64 + terloop)
                For qualoop = 1 To 26
                    colcheck((intloop * 17576) + (lenloop * 676) + (terloop * 26) + qualoop) = Chr$(64 + intloop) & Chr$(64 + lenloop) & Chr$(64 + terloop) & Chr$(64 + qualoop)
                Next qualoop
            Next terloop
        Next lenloop
    Next intloop
    

    Then just use colcheck(yourcolumnnumberhere) and you will get the column heading associated with that letter (i.e. colcheck(703) = AAA

提交回复
热议问题