|
▼櫛田 さん:
> For i = 3 To Range("C3").CurrentRegion.Rows.Count
CurrentRegion.Rows.Countだと、行数になりますが?
iは最終セルの行番号まで繰り返すべき。
Sub test()
Dim i As Long, j As Long
For i = 3 To Cells(Rows.Count, 2).End(xlUp).Row
For j = 3 To Cells(2, Columns.Count).End(xlToLeft).Column
Cells(i, j).FormulaR1C1 = "=R2C*RC2"
Next
Next
End Sub
------------
行数で繰り返すなら
Sub test2()
Dim r As Range
Dim i As Long, j As Long
Set r = Range("C3").CurrentRegion
For i = 2 To r.Rows.Count
For j = 2 To r.Columns.Count
r(i, j).FormulaR1C1 _
= "=R" & r.Row & "C*RC" & r.Column
Next
Next
End Sub
------------
なお繰り返しは不要で、一括で数式を挿入できます。
Sub test3()
Dim r As Range
Set r = Range("C3").CurrentRegion
Intersect(r, r.Offset(1, 1)).FormulaR1C1 _
= "=R" & r.Row & "C*RC" & r.Column
End Sub
|
|