0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

EXCELのVBAでR1C1形式のアドレスをA1形式に変換する方法

Last updated at Posted at 2023-09-16

WorksheetオブジェクトのEvaluateメソッドにアドレスを与えることでRangeオブジェクトが取得できます
このことを応用します

    Dim r As Range
    Set r = Evaluate("=R1C1:R3C4")

ただし、R1C1形式のアドレスを与えるには、アドレスの表示形式をR1C1形式にしておく必要があります

Function R1C1_To_A1(R1C1Address As String) As String
    Application.ReferenceStyle = xlR1C1 '表示形式をR1C1形式に変更
    R1C1_To_A1 = Evaluate("=" & R1C1Address).Address(0, 0) '行列ともに相対参照形式
    Application.ReferenceStyle = xlA1 '表示形式をA1形式に戻す
End Function

Function A1_To_R1C1(A1Address As String) As String
    A1_To_R1C1 = Range(A1Address).Address(, , xlR1C1) '行列ともに絶対参照形式
End Function

Sub Test()
    Debug.Print R1C1_To_A1("R1C1:R3C4")
    Debug.Print A1_To_R1C1("A1:D3")
End Sub

実行結果
A1:D3
R1C1:R3C4

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?