I have a table with 5 columns (B to F) and a variable number of filled rows. I want to copy the last 3 filled cells to a fixed range on the same column starting on row 101.
This the code I'm using:
Dim WSPL As Worksheet
For i = 2 To 6
For j = 7 To 1 Step -1
If Not IsEmpty(WSPL.Cells(j, i).Value) Then
WSPL.Range(Cells(j - 2, i), Cells(j, i)).Copy Destination:=WSPL.Cells(101, i)
Exit For
End If
Next j
Next i
This is returning error:
Run-time error: 1004
Method 'Range' of object'_Worksheet' failed
On line 5 of my code above. What is wrong with this code?
setyour WSPL ?j = 2the expressionj-2in the loop evaluates to0which causes the error. Cant access row or column with an index of 0