How to Use ActiveCell in Excel Using a VBA

Written by jaime avelar
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Use ActiveCell in Excel Using a VBA
Use VBA to add values to your worksheet. (John Foxx/Stockbyte/Getty Images)

If you work with Microsoft Office Excel often it's good to know how to use the "ActiveCell" property to add, get, and even change the format of data in a Worksheet. Visual Basic for Applications (VBA) is a computer programming language used to automate routine tasks. In VBA you can use the "ActiveCell" property to make changes to your data. With VBA you can save time by automating a process instead of performing the same task manually.

Skill level:
Moderately Easy


  1. 1

    Launch Microsoft Office Excel, click the "Developer" tab, and click "Visual Basic."

  2. 2

    Click the "Insert" menu and click "Module" to insert a new code module. Type the following code to start a new sub procedure:

    Private Sub usingActiveCell()

  3. 3

    Copy and paste the following to activate "Sheet1:"


  4. 4

    Copy and paste the following to add a value to "A1," "A2," and "A3:"


    ActiveCell.Value = 3.5


    ActiveCell.Value = 10


    ActiveCell.Value = 20

  5. 5

    Copy and paste the following to highlight the cells with data:

    With ActiveCell

    Range(Cells(.Row, .CurrentRegion.Column), Cells(.Row, .CurrentRegion.Columns.Count + .CurrentRegion.Column - 1)).Interior.ColorIndex = 8
    Range(Cells(.CurrentRegion.Row, .Column), Cells(.CurrentRegion.Rows.Count + .CurrentRegion.Row - 1, .Column)).Interior.ColorIndex = 8

    End With

    Application.ScreenUpdating = True

  6. 6

    Copy and paste the following to display the values added through the "Immediate Window:"


    Debug.Print ActiveCell.Value


    Debug.Print ActiveCell.Value


    Debug.Print ActiveCell.Value

  7. 7

    Copy and paste the following to end the sub procedure:

    End Sub

  8. 8

    Press "Ctrl" and "G" to display the "Immediate Window" and press "F5" to run the procedure.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.