Is an empty Excel range collection possible?

Is it possible to have an empty Excel range collection, that is, can it have an obj object of type Excel.Range so that

obj.Cells.Count = 0 

I have a strong feeling that this is not possible.

Please provide authoritative links that this is really impossible, or provide a counter example.

+4
source share
1 answer

I think this will partially answer your question.
All I can say is that all objects must be Set to call any type of method on them. These are the basics of the OOP concept. You can have an object of any type, for example,
Dim obj as Range
Dim obj as Application
Dim obj as Long
but actually it’s just a reserved room in memory for this variable and is waiting for the link to be assigned.
Therefore, the simple answer is: No, it is not possible to set an empty range object.
Check it out for yourself:

 Sub RangeTest() Dim rng As Range 'Set rng = Range("A1") ActiveWorkbook.Names.Add Name:="rngName", RefersTo:=rng.Address MsgBox "count: " & rng.Cells.Count End Sub 

obviously this is higher however

 Sub RangeTest() Dim rng As Range Set rng = Range("A1") ActiveWorkbook.Names.Add Name:="rngName", RefersTo:=rng.Address MsgBox "count: " & rng.Cells.Count End Sub 


also Range 2010 Object Developer's Guide Excel clearly states

A Range object represents one or more cells and can be used to represent one cell, a row, a column, a selection of cells that contain one or more adjacent blocks of cells, or a three-dimensional range.

+1
source

Source: https://habr.com/ru/post/1489856/


All Articles