You can use the Cells proprietà to refer to a single cell by using row e column index numbers. This proprietà returns a Range object that represents a single cell
In the following example, Cells[5,2] returns cell B5 on Sheet1. The Value proprietà is then set to 10
Workbook.Sheets[1].Cells[5,2].Value := 10;
The Cells proprietà works well for looping through a range of cells, as shown in the following example
With Workbook.Sheets[1] do begin
for i := 1 to 10 do
Cells[i, 1].Value := i;
end;
The Cells proprietà can be applied to Range object, as shown in the following example
With Workbook.Sheets[1].Range['C5', 'G20'] do begin
for i := 1 to Rows.Count do
Cells[i, 1].Value := i;
end;
This example loops through cells C5:H15 on Sheet1. If a cell contains a value less than 0.1, the example replaces that value with 0
With Workbook.Sheets[1].Range['C5', 'H15'] do begin
for i := 1 to Rows.Count do
for j := 1 to Columns.Count do
if Cells[i, j].Value < 0.1 then Cells[i, j].Value := 0;
end;