user2183749
user2183749

Reputation: 23

How to Compare Cell Positions in Excel VBA?

Okay, so basically I want to determine if the row position found for a certain string is below that for another string. If it is, I need to set the value to zero. I've tried many variations of this but it doesn't appear as though I can compare ranges in this way. Is there another way to get the cell position so I can do this comparison?

    If i < 56 Then
        If Rng4(j) < Rng5(i + 1) Then
            Rng4(j).Activate
            X(i, j, 1) = ActiveCell.Offset(0, 1)
            X(i, j, 2) = ActiveCell.Offset(0, 2)
        Else
            X(i, j, 1) = 0
            X(i, j, 2) = 0
        End If
    End If

Upvotes: 2

Views: 826

Answers (1)

grahamj42
grahamj42

Reputation: 2762

You need to compare the Row property of your ranges

If i < 56 Then
    If Rng4(j).Row < Rng5(i + 1).Row Then
        Rng4(j).Activate
        X(i, j, 1) = ActiveCell.Offset(0, 1)
        X(i, j, 2) = ActiveCell.Offset(0, 2)
    Else
        X(i, j, 1) = 0
        X(i, j, 2) = 0
    End If
End If

Upvotes: 2

Related Questions