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 

Will both ranges match the "C: D" range? What is the difference between the two?

+3
vba excel
Jun 17 2018-10-06T00:
source share
1 answer

No, EntireColumn represents a range of "C: D", columns represent columns of cells in a range. If you want to see it in action, here is a small part that shows it. Place non-zero values ​​in the entire range of C2: D3, then place them on C5 and D5. The values ​​in C5 and D5 will not change using the columns (range1), now replace 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 

In addition, Columns indexed, so you can reference the first column, for example:

 r.Columns(1) 
+5
Jun 17 '10 at 0:14
source share



All Articles