NativeExcel for .Net Developer's Reference

IRange.Value Property

Gets or sets the value of the specified range.

[Visual Basic]
PropertyValueAsObject
[C#]
objectValue{get;set;}
[C++]
__propertyObject*get_Value();
__propertyvoidset_Value(Object*);
[JScript]
functiongetValue():Object
functionsetValue(Object);

Property Value

If the cell contains a constant, this property returns the constant. If the cell contains a formula, the Value property returns calculated result of formula. If the range is a one- or two-dimensional range, you can set the Value to an object array of the same dimensions. Similarly, the Value property returns the object array. Setting the Value for a multiple-cell range fills all cells in the range with the value.

Example

This example sets the value of cell A1 on sheet one to 3.14159.

[C#]
book.Worksheets[1].Range["A1"].Value = 3.14159;
[VisualBasic]
book.Worksheets(1).Range("A1").Value = 3.14159
[C++]
book->Worksheets->Item[1]->Range->Item[S"A1"]->Value = 3.14159;
This example is the same as the previous.
[C#]
book.Worksheets[1].Range[1,1].Value = 3.14159;
[VisualBasic]
book.Worksheets(1).Range(1,1).Value = 3.14159
[C++]
book->Worksheets->Item[1]->Range->Item[1,1]->Value = 3.14159;
This example copies the values from A1:F1 range to A2:F2 range.
[C#]
IWorksheet sheet = book.Worksheets[1]; 
sheet.Range["A2:F2"].Value = sheet.Range["A1:F1"].Value;
[VisualBasic]
Dim sheet As IWorksheet = book.Worksheets(1) 
sheet.Range("A2:F2").Value = sheet.Range("A1:F1").Value
[C++]
IWorksheet* sheet = book->Worksheets->Item[1]; 
sheet->Range->Item[S"A2:F2"]->Value = sheet->Range->Item[S"A1:F1"]->Value;
This example demonstrates using a formula.
[C#]
IWorksheet sheet = book.Worksheets[1]; 
sheet.Range["B1"].Value = "=(A1/100)*20";
sheet.Range["B2"].Value = "=SUM(A1:B1)";
sheet.Range["B3"].Value = "=PI()*A3^2/2";
[VisualBasic]
Dim sheet As IWorksheet = book.Worksheets(1) 
sheet.Range("B1").Value = "=(A1/100)*20"
sheet.Range("B2").Value = "=SUM(A1:B1)"
sheet.Range("B3").Value = "=PI()*A3^2/2"
[C++]
IWorksheet* sheet = book->Worksheets->Item[1]; 
sheet->Range->Item[S"B1"]->Value = S"=(A1/100)*20";
sheet->Range->Item[S"B2"]->Value = S"=SUM(A1:B1)";
sheet->Range->Item[S"B3"]->Value = S"=PI()*A3^2/2";

See Also

IRange Interface | NativeExcel Namespace | Formula Property | DisplayValue Property | ClearContents Method