VBA范围变量在剪切后消失了 [英] VBA Range variable gone after cut
问题描述
424错误.有人会告诉我为什么范围变量在剪切后消失了吗?
424 error. Would anyone be kind enough to tell me why the range variable was gone after cut?
with sheets(1)
Dim des as range
set des = .range("A15")
.range("A1:A3").cut des
msgbox(des.row+5)
end with
推荐答案
Range
对象存储对特定单元格的引用,而不是对特定地址的引用.当引用的单元格四处移动时,将跟随Range
对象.例如.如果存储Range("B1")
然后在A和B之间插入一列,则变量现在将具有Range("C1")
,因为B1
已移到右侧.
A Range
object stores a reference to particular cells, not to particular address. When the referenced cells move around, the Range
object will follow. E.g. if you store a Range("B1")
and then insert a column between A and B, your variable will now have Range("C1")
, because your B1
has moved to the right.
当跟踪的单元格不再存在时,Range
实例将变得不可用.
When the tracked cells cease to exist, the Range
instance becomes unusable.
剪切完全替换了实际单元,而不是简单地覆盖它们的内容,因此,Range
正在跟踪的单元不再存在,并且其他某些单元现在将采用A15
的地址.但是,这是一个不同的单元格,因此您的Range
实例不见了.
Cutting replaces the actual cells entirely as opposed to simply overwriting their contents, so the cell your Range
is tracking stops to exist, and some other cell will now assume the address of A15
. That is a different cell though, so your Range
instance is gone.
一个显着的例外是仅销毁Range
的一部分.在这种情况下,Range
接受新的单元格并保持其形状.例如.如果存储Range("A15:A20")
并将Range("A1:A3")
剪切为A15
,则结果范围仍为A15:A20
.
A notable exception is when you destroy only a part of the Range
. In that case the Range
accepts the new cells and maintains its shape. E.g. if you stored Range("A15:A20")
and cut Range("A1:A3")
over A15
, the resulting range would still be A15:A20
.
这篇关于VBA范围变量在剪切后消失了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!