I want to select all non-empty cells from the current cell to the last cell of the row.
If we use
currentRange.End[XlDirection.xlToRight]
this is not a good approach when the non-empty cells are not contiguous link. For example, cells A1, A2, A3, A5, A6 are not empty, then RangeA1.End[XlDirection.xlToRight]
only go as far as A3, that is, the last non-empty cell connected to RangeA1.
Another option:
CreateRange(currentRange, lastRangePossibleinRow).SpecialCells(...)
I have 3 question:
currentRange.End[XlDirection.xlToRight]
seems like an unreliable solution. For example, if currentRange is empty, this will return 1 cell anyway (itself).How do I extend the selection from current cell to the last cell in Row effectively?
CreateRange(currentRange, get_range(currentRange.Row + sheet.Columns.Count.ToString()))
? Perhaps there is a better solution.How to get a collection of cells in this Range that is not empty?
.SpecialCells(xlCellTypeConstants | xlCellTypeFormulas)
will not work, for example, if non is found,.SpecialCells(xlCellTypeConstants)
will throw an exception: no cells found.