To summarize: if the base range of the SpecialCells is just one cell, then the result of range.SpecialCells(xlCellTypeConstants, xlNumbers) yields not just that cell or nothing. I supposed, SpecialCells should yield a range inside that object it is applied... or am I wrong?
I've "developed" a little new excel book, just to show what I don't understand, as follows:
Created a new excel book
Filled the A1:B3, as follows:
A B ... 1 1 12 2 2 22 3 3 32 .
All the other cells of the sheet are untouched.
Inside a new module I've added the following code:
Private Sub test() Dim oSet As Range, oSpec As Range, oUsed As Range Worksheets("Sheet1").Activate Set oSet = ActiveSheet.Range("A1:A1") Set oSpec = oSet.SpecialCells(xlCellTypeConstants, xlNumbers) Set oUsed = ActiveSheet.UsedRange Set oSet = Nothing Set oSpec = Nothing Set oUsed = Nothing End Sub
Running the subroutine, and stopping it at the first range reset, it yields:
oSet.Address = "$A$1" oSpec.Address = "$A$1:$B$3" ' this seems to be wrong; should it be just "$A$1" ? oUsed.Address = "$A$1:$B$3"
Having been changed the value of A1 to A, rerun the sub, and stop at the same place, it gives (consistently with the previous, which shows it works consequtively):
oSet.Address = "$A$1" oSpec.Address = "$B$1","$A$2:$B$3" ' this seems to be wrong; should oSpec be nothing ? oUsed.Address = "$A$1:$B$3"
However, resetting the value of A1 to the original 1, but changing the range of the first Set operation in the Subroutine from just the cell "A1" to a true range of cells "A1:A2", then rerun the sub, and stop at the place, it gives very different (and more expected) result:
oSet.Address = "$A$1:$A$2" oSpec.Address = "$A$1:$A$2" ' this is good oUsed.Address = "$A$1:$B$3"
I would appreciate, if somebody would explain the results. Thanks ahead.
.SpecialCells
as they refer to single or missing range objects. A similar situation of bad returned results can be shown where thexlCellTypeVisible
on the filtered range below the filter's header row with no rows showing actually returns the full filtered range down to the bottom of the worksheet, not nothing. – user4039065