Special Cells Method

This method returns a Range object that represents all the cells that match a specified type and value. The syntax is:

RangeObject.SpecialCells(Type, Value)

The Type parameter specifies the type of cells to include from RangeObject. It can be one of the following XlCellType constants:

Enum XlCellType xlCellTypeComments = -4144 xlCellTypeFormulas = -4123 xlCellTypeConstants = 2 xlCellTypeBlanks = 4 xlCellTypeLastCell = 11 xlCellTypeVisible = 12 End Enum

For instance, the code:

Range("A1:D10").SpecialCells(xlCellTypeBlanks).Select selects all blank cells in the range A1:D10.

The optional Value parameter applies when the Type parameter is either xlCellTypeConstants or xlCellTypeFormulas and identifies more specifically the type of cell to return. In these cases, the Value parameter can be set to one of, or a sum of, the following constants:

Enum XlSpecialCellsValue xlNumbers = 1

'Cells with comments 'Cells with formulas 'Cells with constants 'Blank cells 'Last cell in range 'All visible cells xlTextValues = 2 xlLogical = 4 xlErrors = 16 End Enum

For instance, the code:

Range("A1:D10").SpecialCells(xlCellTypeConstants, xlTextValues).Select selects only the cells with text (as opposed to numbers) within the range A1:D10.

0 0

Post a comment