Poliquin
Poliquin

Reputation: 2987

Excel 2011 VBA - Set Range

I am puzzled by how Range() works.

I have the following code

Option Explicit
Option Base 1

Sub ShowRange()
   Dim rng As Range
   Set rng = WorkSheets(1).Range("B:D")
End Sub

I noticed that rng returns D as column number 4. Shouldn't it return as column number 3?

Bregs, Yakult121

Upvotes: 0

Views: 4614

Answers (1)

GSerg
GSerg

Reputation: 78134

The Column property is a global, sheet-wide column number of the cell.

If rng = WorkSheets(1).Range("B:D"), then column D is rng.Columns(3), because D is the third column in rng. But rng.Columns(3).Column is 4.

Upvotes: 4

Related Questions