Excel Worksheets - Range Cells Select

The VBA code fragments below are included in the Code VBA fragments library.
Fragments are snippets of code you can insert in your procedures.
Each item between braces correspond to a variable of the given type.
They are replaced with the new or existing variables by Fragment Builder in Code-VB tools.

Bottom Cell in Column in Region


{RANGE}.End(xlDown)

Cell at the address given by r row and c column


{RANGE}.Cells({LONG:rw}, {LONG:cl})     

Cells containing constants


On Error GoTo SpecialCells_Error
Set {RANGE:rngCellsWithConstants} = {RANGE:rng}.SpecialCells(xlCellTypeConstants)
<cursor>
GoTo SpecialCells_Finish
SpecialCells_Error: 'If nothing you will get a run time error '1004'
Resume SpecialCells_Finish
SpecialCells_Finish:

Cells containing formulas


On Error GoTo SpecialCells_Error
Set {RANGE:rngCellsWithFormulas} = {RANGE:rng}.SpecialCells(xlCellTypeFormulas)
<cursor>
GoTo SpecialCells_Finish
SpecialCells_Error: 'If nothing you will get a run time error '1004'
Resume SpecialCells_Finish
SpecialCells_Finish:

Cells containing notes


On Error GoTo SpecialCells_Error
Set {RANGE:rngCellsWithComments} = {RANGE:rng}.SpecialCells(xlCellTypeComments)
<cursor>
GoTo SpecialCells_Finish
SpecialCells_Error: 'If nothing you will get a run time error '1004'
Resume SpecialCells_Finish
SpecialCells_Finish:

Cells having validation criteria


On Error GoTo SpecialCells_Error
Set {RANGE:rngCellsWithValidation} = {RANGE:rng}.SpecialCells(xlCellTypeAllValidation)
<cursor>
GoTo SpecialCells_Finish
SpecialCells_Error: 'If nothing you will get a run time error '1004'
Resume SpecialCells_Finish
SpecialCells_Finish:

Cells with same format


'All cells in the specified range that contain the same format as the *first* cell specified in range.
On Error GoTo SpecialCells_Error
Set {RANGE:rngCellsWithSameFormat} = {RANGE:rng}.SpecialCells(xlCellTypeSameFormatConditions)
<cursor>
GoTo SpecialCells_Finish
SpecialCells_Error: 'If nothing you will get a run time error '1004'
Resume SpecialCells_Finish
SpecialCells_Finish:

Cells with same validation


'All cells in the specified range that contain the same validation as the *first* cell specified in range.
On Error GoTo SpecialCells_Error
Set {RANGE:rngCellsWithSameValidation} = {RANGE:rng}.SpecialCells(xlCellTypeSameValidation)
<cursor>
GoTo SpecialCells_Finish
SpecialCells_Error: 'If nothing you will get a run time error '1004'
Resume SpecialCells_Finish
SpecialCells_Finish:

Current Region from Range


{RANGE}.CurrentRegion

Last Cell in Row in Region


{RANGE}.End(xlToRight)

Last Cell in Used Range


Set {RANGE:rngLastCell} = {RANGE:rng}.SpecialCells(xlCellTypeLastCell)

Nth cell in the range


{RANGE}.Cells({LONG}) 

Select non-adjacent cells


'Select non-adjacent cells (example has two, can be extended)
Application.Union({WORKSHEET}.Cells({LONG:rw1},{LONG:cl1}), {WORKSHEET}.Cells({LONG:rw2},{LONG:cl2})).Select     

Selects all the cells in the Worksheet


{WORKSHEET}.Cells.Select

Set Cell using A1 notation


Set {RANGE} = {WORKSHEET}.Range({STRING:cl1} & {LONG:rw1} )                        

Top Cell in Column in Region


{RANGE}.End(xlUp)

Excel Worksheets Range Cells Select Top Cell in Column in Region