Attached you find a snippet of an Excel macro, in which the part in the for-loop always throws an error:
run-time error 1004 "application defined or object defined error"
I have checked online and it is advised to correct the object's qualification by adding a dot before the cells(xy)
expression. However, if I change the code to Range(.Cells(xyz))
, I am given another error:
invalid or unqualified reference
Any advice on how to fix this problem?
Sub Run()
Dim n As Integer
n = Worksheets("Results").Cells(10, 8).Value
For i = 1 To n
ActiveWorkbook.RefreshAll
Worksheets("VBA").Range(Cells(1, i + 3), Cells(12, i + 3)).Value = Worksheets("Results").Range("F3:F14").Value
Next i
Worksheets("Results").Range("J3:L14").Value = Worksheets("VBA").Range("A1:C12").Value
Worksheets("VBA").Range(Cells(1, 4), Cells(12, i + 3)).Clear
End Sub