SpenceLegend
SpenceLegend

Reputation: 23

Set an offset value for each cell in a range VBA Excel

I am trying to compare a value to each cell in a range. Once there is a match, I want to set another variable to old the value that is offset 3 columns over.

For Each i In Worksheets("SFDC Input").Range("D2:D20").Cells
    If ProductFamily = i Then
        i.Offset(0, -3).Value = ID
    End If
Next

ProductFamily is the value I am comparing to i. I want ID to be the value holder.

Upvotes: 1

Views: 14474

Answers (1)

Brian Phillips
Brian Phillips

Reputation: 4425

It looks as though your assignment (=) is backwards. You're setting i.Offset(0, -3).Value to ID instead of setting ID to the value.

Try the following:

ID = i.Offset(0, -3).Value

From MSDN:

The = operator assigns the value on its right to the variable or property on its left.

Upvotes: 11

Related Questions