VBA Finding the next column based on an input value

后端 未结 5 1425
隐瞒了意图╮
隐瞒了意图╮ 2021-01-27 21:56

In a program that I\'m trying to write now I take two columns of numbers and perform calculations on them. I don\'t know where these two columns are located until the user tell

5条回答
  •  孤街浪徒
    2021-01-27 22:17

    Make use of the Asc() and Chr() functions in VBA, like so:

    Dim first_Column As String
    Dim second_Column As String
    
    first_Column = Range("B2").Text
    second_Column = Chr(Asc(first_Column) + 1)
    

    The Asc(s) function returns the ASCII code (in integer, usually between 0 and 255) of the first character of a string "s".

    The Chr(c) function returns a string containing the character which corresponds to the given code "c".

    Upper case letters (A thru Z) are ASCII codes 65 thru 90. Just google ASCII for more detail.

    NOTE: The above code will be fine so long as the first_Column is between "A" and "Y"; for columns "AA" etc., it will take a little more work, but Asc() and Chr() will still be the ticket to coding for that.

提交回复
热议问题