Ad space (banner)
Lesson 9 / 20

Reading and writing cells (Range and Cells)

This lesson covers the basics of working with Excel cells from VBA.

You point at a particular cell with Range("A1") or Cells(1, 1), and read or write its contents through the .Value property.

The sample code writes a value into a cell with Range("A1").Value = 100 and displays what it reads back with Range("A1").Value.

A common early stumble is choosing between Range("A1") (A1 notation) and Cells(1, 1) (row and column as numbers). Range suits a fixed position; Cells is handier when a For loop is walking down the rows.

In professional work, most of an Excel macro is built around reading and writing cells — it is the most basic and most important VBA operation there is.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run VBA directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)