Microsoft Excel Training Videos

Refer to Excel Cells by Using Index Numbers in a macro


You can use the Cells property to refer to a single Excel cell by using row and column index numbers in a macro in Microsoft Excel. This property returns an Excel Range object that represents a single cell. In the following example, Cells(2,4) returns product of cells(2,2) and cells(2,3) of Excel Sheet1.
Sub MyValue()
Worksheets("sheet1").Cells(2, 4).Value = Cells(2, 2).Value * Cells(2, 3).Value
End Sub
The Cells property works well for looping through a range of Excel cells because you can substitute variables for the index numbers, as shown in the following example.
Sub CycleThrough()
Dim Counter As Integer
For Counter = 1 To 20
Worksheets("Sheet1").Cells(Counter, 3).Value = Counter
Next Counter
End Sub
This Excel training video demonstrates how to perform a calculation after accessing the Excel cells.





Custom Search

Further links

How to: Refer to Cells by Using Index Numbers

Microsoft Excel Training Videos