vba Range.Columns 和 Range.EntireColumn 有什么区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3058062/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between Range.Columns and Range.EntireColumn
提问by Laurent
Dim r as Range
Set r = Range("C2:D3")
Dim r1 as Range, r2 as Range
Set r1 = r.EntireColumn
Set r2 = r.Columns
Won't both ranges represent the range "C:D"? What is the difference between the two?
不是两个范围都代表范围“C:D”吗?两者有什么区别?
回答by Lance Roberts
No, EntireColumn represents the range "C:D", Columns represents the columns of the cells in the range. If you want to see this in action, here's a small sub that shows this. Place non-zero values in the entire range C2:D3, then place some in C5 and D5. The values in C5 and D5 won't change with Columns (range1), now substitute EntireColumn (range2) and see what happens.
不,EntireColumn 表示范围“C:D”,Columns 表示该范围内单元格的列。如果你想看到它的实际效果,这里有一个显示这一点的小子。在整个范围 C2:D3 中放置非零值,然后在 C5 和 D5 中放置一些。C5 和 D5 中的值不会随着 Columns (range1) 而改变,现在替换 EntireColumn (range2) 看看会发生什么。
Sub Test()
Dim range1 As Range
Dim range2 As Range
Set range1 = Range("C2:D3").Columns
Set range2 = Range("C2:D3").EntireColumn
range1.Value = 0
End Sub
Also, Columns
is indexed, so you can reference the first column like:
此外,Columns
已编入索引,因此您可以引用第一列,例如:
r.Columns(1)