Hi, VBA beginner here. I've got a loop where I want to compare one value in an array to the one before it, and put data in a worksheet if they don't match. I do this by comparing value (k) to value (k - 1). I'm out of bounds in evaluating the first loop because k always is the first position in the array (1 in my case). I've come up with a workaround, as shown in the first two lines of my code, but it is unwieldy for other, more complicated loops. The example below is the simplest I could find that fully represents the problem.

So I'm wondering if there is a more elegant way to do this. The array is ~800 strings long and the macro will be run infrequently, so performance isn't a big issue. Thanks

    Range("B5").Offset(1) = MyArray(1, 2)
    j = 2

    For k = 2 To MyArrayCount
        If MyArray(k, 4) <> MyArray(k - 1, 4) Then
            Range("B5").Offset(j) = MyArray(k, 2)
        j = j + 1
        End If
    Next k