1

I have written this example code to reporduce the error:

Sub test()

Dim rng As Range
Dim cell As Range

Set rng = ThisWorkbook.Worksheets(1).Range("C1:C3")

For Each cell In rng
    If cell.Value2 = cell.Offset(-1, 0).Value2 Then
    cell.Offset(1, 0) = "TRUE"
    End If
Next cell

End Sub

In the line If cell.Value = cell.Offset(-1, 0).Value2 I get an Application or Object defined error but I have no idea why. Usually it should check for C1 if B1 has the same value. Maybe I am just blind. Could anyone tell me why this is not working?

1 Answer 1

1

Offset property of Range object has the order of arguments: Offset(RowOffset, ColumnOffset), your code refers to the cells C0, which doesn't exist, try Offset(0,-1).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.