0
votes

I am sort of a novice with VBA. running into an issue. I am trying to say If this value in this table is 2 then execute these formulas if not stop and give a message "Not Done."

If "=VLOOKUP(D8,'Sheet'!B:J,9,false)" = 2 Then

Range("I8").Select
ActiveCell.Formula = "=VLOOKUP(D8,'Sheet'!B:J,2,false)"
Range("J8").Select
ActiveCell.Formula = "=VLOOKUP(D8,'Sheet'!B:J,3,false)"
Range("K8").Select
ActiveCell.Formula = "=G8-N8"

Else

Range("J8").Select
ActiveCell.Formula = "Not Done"
Range("K8").Select
ActiveCell.Formula = "Not Done"


Range("I8:K8").Select
Selection.AutoFill Destination:=Range("I8:K" & Range("A" & rows.count).End(xlUp).row)
Range(Selection, Selection.End(xlDown)).Select
1
If I understand what you are trying to do, it might be better to just bake the "is 2 or not" logic into the formula directly.BigBen
Please edit your question title to something that isn't simply repeating the information already available in the tags. Your title should describe a problem or question in a way that will have meaning for future users of the site who are searching for a solution to a similar problem. Your current title is not helpful for that purpose. Repeating the tags is meaningless. Thanks.Ken White
If "=VLOOKUP(D8,'Sheet'!B:J,9,false)" = 2 Then is problematic because "=VLOOKUP(D8,'Sheet'!B:J,9,false)" is just text (String), not a formula that is evaluated. It's no different than saying If "abracadabra" = 2.BigBen

1 Answers

0
votes

In VBA:

If Application.Vlookup(ActiveSheet.Range("D8").Value, _
              Sheets("Sheet").Range("B:J"), 9, False) = 2 Then