How to change a cell value with vba

Written by jaime avelar
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to change a cell value with vba
Update Excel values in VBA. (John Foxx/Stockbyte/Getty Images)

You may need to change the value in a cell when working with Excel and Visual Basic for Applications, or VBA. With VBA you can modify cells automatically without the need to manually change the values. You can accomplish this task by using the Range object in VBA to select the cell you want to change. Once the cell is selected, then you can use the ActiveCell property to change its value or other properties.

Skill level:
Moderately Easy


  1. 1

    Launch "Microsoft Office Excel" and type "data in A1" in cell A1. Click the "Developer" tab, and click "Visual Basic" to open the VBA Editor Window.

  2. 2

    Click the "Insert" menu, and click "Module" to insert a new module.

  3. 3

    Create a new String variable by typing the following:

    Dim data As String

  4. 4

    Copy and paste the following code to change the value in cell A1:


    data = Range("A1").Value
    If data = "data in A1" Then
        ActiveCell.Value = "A1 data changed"
        MsgBox "Data is OK."

    End If

  5. 5

    Press "F5" to run the procedure and change the value in A1. Run the procedure a second time, and you will get a message box stating that the data are OK.

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.