本文介绍了Range1.Range2返回奇怪的地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用Range1.Range2时,我已经使用Range2来扩展或收缩Range1.尝试回答问题时,我遇到了Range2与Range1没有关系的用法.我以为这会返回一个错误,但是却返回了一个我不明白的地址.

When I have used Range1.Range2, I have used Range2 to expand or contract Range1. While attempting to answer a question, I encountered a use where Range2 had no relationship to Range1. I assumed this would return an error but instead it returned an address which I do not understand.

此宏:

Sub Test()

  Debug.Print Range("A2").Range("B1").Address
  Debug.Print Range("B3").Range("B5").Address
  Debug.Print Range("C4").Cells(10, 5).Address
  Debug.Print Range("D5").Cells(10, 15).Address
  Debug.Print Range("D5:F10").Cells(10, 15).Address
  Debug.Print Cells(5, 6).Cells(12, 15).Address
  Debug.Print "======"
  ' Specifying the sheet does not seem to affect the result
  Debug.Print Range("B3").Cells(15, 1).Address
  Debug.Print ActiveSheet.Range("B3").Cells(15, 1).Address
  Debug.Print Sheets("Sheet1").Range("B3").Cells(15, 1).Address

End Sub

产生以下输出:

$B$2
$C$7
$G$13
$R$14
$R$14
$T$16
======
$B$17
$B$17
$B$17

在我执行的所有此类测试中,它都显示为:

In all the tests of this type I have performed, it appears:

Range1.Range2

等效于:

Cells(Range1.Row + Range2.Row - 1, Range1.Column + Range2.Column - 1)

我希望我不会经历DOH的时刻,但是有人能够提供解释吗?

I hope I am not about to experience a DOH moment but is anyone able to offer an explanation?

我正在使用Excel2003.其他版本的用户是否从此宏中获得相同的输出?

I am using Excel 2003. Do users of other releases get the same output from this macro?

推荐答案

MSDN :

正如@Tony所注意到的, Range.Range 的行为与 Offset.Resize 非常相似,即 Range("C3").Range("B1:C3).Address 返回与 Range(" C3).Offset(0,1).Resize(3,2).Address - $D $ 3:$ E $ 5

And as @Tony noticed, behaviour of Range.Range quite similar to Offset.Resize, i.e. Range("C3").Range("B1:C3").Address returns the same address as Range("C3").Offset(0, 1).Resize(3, 2).Address –– $D$3:$E$5

这篇关于Range1.Range2返回奇怪的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-10 23:13