Technically, Range
and Range.Cells
are not equivalent. There is a small but important difference.
However in your particular case, where you
- Construct the range with
Range("something")
, and
- Are only interested in the
.Value
of that range,
it makes no difference at all.
There is a handy clause in VB, For Each
, that enumerates all elements in a collection. In the Excel object model, there are convenient properties such as Columns
, Rows
, or Cells
, that return collections of respective cell spans: a collection of columns, a collection of rows, or a collection of cells.
From how the language flows, you would naturally expect that For Each c In SomeRange.Columns
would enumerate columns, one at a time, and that For Each r In SomeRange.Rows
would enumerate rows, one at a time. And indeed they do just that.
But you can notice that the Columns
property returns a Range
, and the Rows
property also returns a Range
. Yet, the former Range
would tell the For Each
that it's a "collection of columns", and the latter Range
would introduce itself as a "collection of rows".
This works because apparently there is a hidden flag inside each instance of the Range
class, that decides how this instance of Range
will behave inside a For Each
.
Querying Cells
off a Range
makes sure that you get an instance of Range
that has the For Each
enumeration mode set to "cells". If you are not going to For Each
the range to begin with, that difference makes no difference to you.
And even if you did care about the For Each
mode, in your particular case Range("A1").Resize(2,3)
and Range("A1").Resize(2,3).Cells
are the same too, because by default the Range
is constructed with enumeration mode of "cells", and Resize
does not change the enumeration mode of the range it resizes.
So the only case that I can think of where querying Cells
from an already existing Range
would make a difference, is when you have a function that accepts a Range
as a parameter, you don't know how that Range
was constructed, you want to enumerate individual cells in that range, and you want to be sure that it's cells For Each
is going to enumerate, not rows or columns:
function DoSomething(byval r as range)
dim c as range
'for each c in r ' Wrong - we don't know what we are going to enumerate
for each c in r.cells ' Make sure we enumerate cells and not rows or columns (or cells sometimes)
...
next
end function