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

Other People Are Reading

Instructions

  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:"

    Worksheets("Sheet1").Activate

  4. 4

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

    Range("A1").Select

    ActiveCell.Value = 3.5

    Range("A2").Select

    ActiveCell.Value = 10

    Range("A3").Select

    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:"

    Range("A1").Select

    Debug.Print ActiveCell.Value

    Range("A2").Select

    Debug.Print ActiveCell.Value

    Range("A3").Select

    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

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

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