The Value property

The Value property represents the value contained in a cell. It's a read-write property, so your VBA code can either read or change the value.

The following statement displays a message box that shows the value in cell A1 on Sheetl:

MsgBox Worksheets("Sheet1").Range("A1").Value

It stands to reason that you would read the Value property only for a single-cell Range object. For example, the following statement generates an error:

MsgBox Worksheets("Sheet1").Range("A1:C3").Value

You can, however, change the Value property for a range of any size. The following statement enters the number 123 into each cell in a range:

Worksheets("Sheet1").Range("A1:C3").Value = 123

Value is the default property for a Range object. In other words, if you omit a property for a Range, Excel uses its Value property. The following statements both enter a value of 75 into cell A1 on Sheetl:

Worksheets("Sheet1").Range("A1").Value = 75 Worksheets("Sheet1").Range("A1") = 75

0 0

Post a comment