Range.Columns和Range.EntireColumn有什么区别 [英] What is the difference between Range.Columns and Range.EntireColumn
问题描述
Dim r as Range
Set r = Range("C2:D3")
Dim r1 as Range, r2 as Range
Set r1 = r.EntireColumn
Set r2 = r.Columns
两个范围都不代表范围"C:D"吗?两者有什么区别?
Won't both ranges represent the range "C:D"? What is the difference between the two?
推荐答案
否,EntireColumn表示范围"C:D",Columns表示该范围中单元格的列.如果您想看到实际效果,这里有一个小子程序显示了这一点.将非零值放置在整个范围C2:D3中,然后将一些放置在C5和D5中. C5和D5中的值不会随着Columns(范围1)而改变,现在替换为EntireColumn(范围2),然后看看会发生什么.
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.
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
此外,Columns
已建立索引,因此您可以引用第一列,例如:
Also, Columns
is indexed, so you can reference the first column like:
r.Columns(1)
这篇关于Range.Columns和Range.EntireColumn有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!