Export (0) Print
Expand All

Working with the Active Cell

Office 2007

The ActiveCell property returns a Range object that represents the cell that is active. You can apply any of the properties or methods of a Range object to the active cell, as in the following example.

Sub SetValue()
    Worksheets("Sheet1").Activate
    ActiveCell.Value = 35
End Sub
Bb211461.vs_note(en-us,office.12).gif  Note
You can work with the active cell only when the worksheet that it is on is the active sheet.

Moving the Active Cell

You can use the Activate method to designate which cell is the active cell. For example, the following procedure makes B5 the active cell and then formats it as bold.

Sub SetActive()
    Worksheets("Sheet1").Activate
    Worksheets("Sheet1").Range("B5").Activate
    ActiveCell.Font.Bold = True
End Sub
Bb211461.vs_note(en-us,office.12).gif  Note
To select a range of cells, use the Select method. To make a single cell the active cell, use the Activate method.

You can use the Offset property to move the active cell. The following procedure inserts text into the active cell in the selected range and then moves the active cell one cell to the right without changing the selection.

Sub MoveActive()
    Worksheets("Sheet1").Activate
    Range("A1:D10").Select
    ActiveCell.Value = "Monthly Totals"
    ActiveCell.Offset(0, 1).Activate
End Sub

Selecting the Cells Surrounding the Active Cell

The CurrentRegion property returns a range of cells bounded by blank rows and columns. In the following example, the selection is expanded to include the cells adjoining the active cell that contain data. This range is then formatted with the Currency style.

Sub Region()
    Worksheets("Sheet1").Activate
    ActiveCell.CurrentRegion.Select
    Selection.Style = "Currency"
End Sub


Community Additions

ADD
Show:
© 2014 Microsoft