Refer to Cells by Using Index Numbers
Use the Cells property to refer to a single cell by using row and column index numbers. This property returns a Range object that represents a single cell. In the following example, Cells(6,1)
returns cell A6 on Sheet1. The Value property is then set to 10.
Sub EnterValue()
Worksheets("Sheet1").Cells(6, 1).Value = 10
End Sub
The Cells property works well for looping through a range of 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
Note If you want to change the properties of (or apply a method to) a range of cells all at once, use the Range property. For more information, see Refer to Cells and Ranges by Using A1 Notation.
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for