You don't have to activate or select a cell to assign a value. The value property can be read or written directly, given the proper object (Range
or Cell
, etc.). You can initialize a Range
variable and let that hold the cell address you want to access later on.
The above said, if you just want to assign values over an iteration of cells, there's no need to really assign a dynamic range reference and use offset. A simple loop would do. See following code and example.
Sub IterateExample()
'Initialize variables.
Dim wb As Workbook
Dim ws As Worksheet
Dim x As Integer, y As Integer, i As Integer, j As Integer
' Assign to object.
Set wb = ThisWorkbook
Set ws = wb.Sheets("Sheet1")
' Assign values.
x = 10
y = 10
Application.ScreenUpdating = False 'Hide updates from viewer/user.
' Simple iteration.
For i = 1 To x
For j = 1 To y
'i is row index, j is column index.
ws.Cells(i, j).Value = i * j 'Use .Value directly, no need to .Select or .Activate
Next
Next
Application.ScreenUpdating = True 'Return to original setting.
End Sub
Result is simple enough:

However, if you really have to have a range reference that updates, a loop can also solve that, just re-assign the object inside the loop.
Sub OffsetExample()
'Initialize variables.
Dim wb As Workbook
Dim ws As Worksheet
Dim r As Range, i As Integer
'Assign to object.
Set wb = ThisWorkbook
Set ws = wb.Sheets("Sheet1")
'Assign range.
Set r = ws.Range("A1")
Application.ScreenUpdating = False 'Hide updates from viewer/user.
'Iteration of offset.
For i = 1 To 10
r.Value = i * i
Set r = r.Offset(1, 1) 'Move range reference 1 row down, 1 column right
Next
Application.ScreenUpdating = True 'Return to original setting.
End Sub
Result is as follows:
