bermudamohawk
bermudamohawk

Reputation: 17

Placing a variable within an inserted formula

The loop is already in place, but I can't seem to get the syntax for replacing A2 with a correct variable.

For Each c In rng1
    If WorksheetFunction.CountIf(rng2, c.Value) = 0 Then
        sh3.Cells(Rows.Count, 1).End(xlUp)(2) = c.Value
        sh3.Cells(Rows.Count, 2).End(xlUp)(2).Formula = _
            "=INDEX(MatList!$D$13:$D$62,MATCH(A2,MatList!$A$13:$A$62,0))"
    End If
Next

Upvotes: 0

Views: 46

Answers (2)

bermudamohawk
bermudamohawk

Reputation: 17

thank you for that. getting closer. seems like i'm in a paradox now though the variable "x" has a value of 0 and 6 at the same time. curious

Upvotes: 0

ManishChristian
ManishChristian

Reputation: 3784

Just replace your formula from:

"=INDEX(MatList!$D$13:$D$62,MATCH(A2,MatList!$A$13:$A$62,0))"

To:

"=INDEX(MatList!$D$13:$D$62,MATCH(" & YourVariableName & ",MatList!$A$13:$A$62,0))"

Upvotes: 3

Related Questions