Vba-从范围数组返回单元格地址

时间:2017-05-30 19:15:08

标签: excel-vba vba excel

我在工作表上读取了一个范围并将其放入数组中。

Dim Arr() As Variant
Arr = Range("B3:G11")
Dim R As Long
Dim C As Long
For R = 1 To UBound(Arr, 1)
    For C = 1 To UBound(Arr, 2)
        Debug.Print Arr(R, C)
    Next C
Next R

返回单元格的值。有没有办法获取单元格的地址?!

提前谢谢。

1 个答案:

答案 0 :(得分:1)

使用此代替Debug.Print Arr(R, C)

Debug.Print Cells(R+2, C+1).Address(1,1)

还可以填充一系列范围:

Dim Arr() As Range
Dim rng As Range
ReDim Arr(1 To Range("B3:G11").Rows.Count, 1 To Range("B3:G11").Columns.Count) As Range
For Each rng In Range("B3:G11")
    Set Arr(rng.Row - 2, rng.Column - 1) = rng
Next rng
Dim R As Long
Dim C As Long
For R = 1 To UBound(Arr, 1)
    For C = 1 To UBound(Arr, 2)
        Debug.Print Arr(R, C).Address
    Next C
Next R