30 Advanced Excel Tips for 2026

Excel Champs / VBA / VBA Enter Value in a Cell (Set, Get and Change)
By Puneet Gogia (Microsoft MVP)

VBA Enter Value in a Cell (Set, Get and Change)

30+ Advanced Excel Tips for 2026

No spam. Only Excel Stuff. God Promise. 😊

Write to a cell with Range("A1").Value = 100 and read from it with x = Range("A1").Value. Cells(1, 1) is the same cell by row and column number, which is easier inside loops.

Name the sheet when the code might run with another sheet active: Worksheets("Data").Range("A1").Value = Date. A bare Range("A1") always means the active sheet.

To write one value to many cells, assign it to the whole range: Range("A2:A100").Value = 0. To copy values from another range, assign range to range: Range("C2:C10").Value = Range("A2:A10").Value. Both ranges must be the same size.

Check the type before you calculate. Range("A1").Value + 1 stops with a type mismatch when A1 holds text, so test it first with If IsNumeric(Range("A1").Value) Then. Use .Text to get the value as it’s displayed, with its number format, and .Formula to get the formula.

For a cell holding a date, .Value returns a Date and .Value2 returns the underlying serial number, which is faster in large loops.

Key Notes

Set Cell Value using VBA Code

To set a cell value, you need to use the “Value” property, and then you need to define the value that you want to set. Here I have used some examples to help you understand this.

1. Enter a Value in a Cell

Let’s say you need to enter the value “Done” in cell A1. In that case, the code would be something like the below:

Range("A1").Value = "Done"
set-cell-value

As you can see, I have first defined the cell address where I want to add the value, and then the value property. In the end, I have assigned the value “Done” (enclosed in double quotation marks, as it’s text) using an equal “=” sign. You can also use the “Cells” property, just like the following code.

Cells(1, 1).Value = "Done"

The above code also refers to cell A1. Apart from this, there is one more way that you can use, and that’s by not using the Value property and assigning the value to the cell directly.

Cells(1, 1) = "Done"

But it is recommended to use the Value property to enter a value in a cell. Now let’s say you want to enter a number in a cell. In that case, you don’t need to use double quotation marks. You can write the code like the following.

Range("A1") = 99

You can also use DATE and NOW (VBA Functions) to enter a date or a timestamp in a cell using a VBA code.

Range("A1").Value = Date
Range("A2").Value = Now

And if you want to enter a value in the active cell, then the code you need would be like this:

ActiveCell.Value = Date

2. Using an Input Box

If you want a user to specify a value to enter in a cell, you can use an input box. Let’s say you want to enter the value in cell A1, the code would be like this:

use-input-box-for-value
Range("A1").Value = _
InputBox(Prompt:="Type the value you want enter in A1.")

In the above code, cell A1 gets the value returned by the input box, which is the value entered by the user. If the user clicks Cancel, the input box returns an empty text, and cell A1 is cleared.

3. From Another Cell

You can also set cell values using the value from another cell. Let’s say you want to add the value from cell B1 to cell A1; the code would be:

Range("A1") = Range("B1").Value
set-cell-value-using-value-from-another-cell

You can also refer to cell B1 without using the value property.

Range("A1") = Range("B1")

4. Set Value in an Entire Range

Imagine you want to enter values in multiple cells or a range of cells instead of a single cell. In that case, you need to write code like the below:

Range("A1:A10").Value = Date
Range("B1, B10").Value = Now
set-value-in-entire-range

In the first line of code, you have an entire range from cell A1 to A10, and in the second line, there are two cells, B1 and B10.

Get Cell Value

As I said, you can use the same Value property to get the value from a cell.

1. Get Value from the ActiveCell

Let’s say you want to get the value from the active cell. In that case, you need to use the following code.

Range("A1").Value = ActiveCell.Value
get-cell-value

In the above code, you have used the value property with the active cell and then assigned that value to cell A1.

2. Assign to a Variable

You can also get a value from a cell and assign it to a variable.

assign-to-a-variable

In the above code, you have the variable “i,” which has the date as its data type. In the second line of the code, the value from cell A1 is assigned to the variable.

Sub get_value_in_variable()
Dim i As Date
i = Range("A1").Value
MsgBox i
End Sub

Cell A1 needs to have a date (or a number) for this code; text that isn’t a date gives the Type Mismatch error (Error 13). If you don’t know what the cell holds, declare the variable as Variant.

3. Show in a MsgBox

Now imagine you want to show the value from cell A1 using a message box. In this case, the code would be as follows:

MsgBox Range("A1").Value
show-in-a-msgbox

In the above code, the message box will take the value from cell A1 and show it to the user.

msgbox-take-value

Change Cell Value

You can also change a cell value, and I have shared a few examples here to help you understand this.

1. Add a Number to an Existing Number

Let’s say you want to add one to the number in cell A1. You can use the following code.

Range("A1").Value = Range("A1").Value + 1

The above code assigns a value to cell A1 by taking the value from cell A1 itself and adding one to it. But you can also use VBA IF THEN ELSE to write a condition to change only when there is a number in the cell.

If IsNumeric(Range("A1").Value) Then
  Range("A1").Value = Range("A1").Value + 1
End If

2. Remove the First Character from the Cell

The following code removes the first character from the cell value and assigns the rest of the value back to the cell.

Range("A1").Value = Right(Range("A1").Value, Len(Range("A1").Value) - 1)

It takes the rightmost portion of the value of cell A1, which is all the characters except the first one (Len – 1), and assigns it back to cell A1. So, the first character is removed. If A1 is empty, Len – 1 is -1 and Right gives an error, so check that the cell isn’t empty first.

Value vs Text vs Value2

A cell has three properties that read what’s in it, and they can give different results for the same cell:

  • Value: the value in the cell, with dates as dates and currency as Currency.
  • Value2: the same as Value, but dates and currency come back as plain numbers (a date is a serial number like 45658).
  • Text: what you see in the cell with its number format, as text. If the column is too narrow, you get “####”. Text can only be read, not set.

Set a Cell Value on Another Sheet

All the codes above work on the active sheet. To set or get a value on another sheet (or workbook), refer to the sheet first. You don’t need to activate it:

Sub value_on_another_sheet()
Worksheets("Sheet2").Range("A1").Value = "Done"
Workbooks("Book2.xlsx").Worksheets("Sheet1").Range("B1").Value = _
Worksheets("Sheet2").Range("A1").Value
End Sub

And if you want to enter a formula instead of a value, use the Formula property, like Range(“A1”).Formula = “=SUM(B1:B10)”. To clear the value, use Range(“A1”).ClearContents.

Frequently Asked Questions

Why does my number go into the cell as text?

Because it’s in double quotation marks or comes from a text variable or an input box. Remove the quotes, or convert it with CDbl or Val before you assign it, like Range(“A1”).Value = CDbl(InputBox(“Enter a number”)).

How do I set the same value in many cells?

Assign it to the whole range in one line, like Range(“A1:A10”).Value = 0, as shown above. It’s much faster than a loop.

What does a cell value return for an empty cell?

It returns Empty, which works as 0 in a calculation and as “” in text. Use IsEmpty(Range(“A1”).Value) to check for it.

Puneet Gogia

Written by

Puneet Gogia

Microsoft MVP — Excel · Founder, Excel Champs

Twelve years of teaching Excel, and a decade before that using it as a data analyst. Every tutorial here is written from a file I actually built.

3M+ readers helped
1,000+ tutorials written
Since 2015 teaching Excel