As the title says, I want to loop from cell i to the last non-empty cell. But I keep getting a type mismatch error even though I am declaring it the same type.
Dim wsList as Worksheet
Dim wsCode as Worksheet
Dim i as Variant
Dim j as Long
Dim LastCell as Variant
Dim LastCell2 as Long
With wsList
LastCell = .Cells(.Rows.Count, "G").End(xlUp)
LastCell2 = .Cells(.Rows.Count, "F").End(xlUp)
End With
For i = 1 To LastCell
wsList.Range("G2").Offset(i - 1).Copy _
wsCode.Range("C2").Offset((i - 1) * 14)
Next i
For j = 1 To LastCell2
wsCode.Range("F11").Offset((j - 1) * 14).Value = _
wsList.Range("F2").Offset(j - 1).Value
Next j
End Sub
Mismatch error occurs between LastCell and i even though I declared them both as variant. I also tried declaring them as string but still getting the same error. The data type in that particular column is "AB12345" including quotation marks. How can I fix this?
Thanks in advance!