Excel VB: how do I call VLOOKUP if condition is met?

Viewed 93

I've got a data set that comes out of Oracle, but a number of the records are missing the GEO data (AMER, EMEA, APAC) in column E and instead show "-". I am formatting and processing this data using VB and I have everything working save for this one piece.

What I want to do is to call a VLOOKUP formula to replace those "-" values with the correct GEO based on the country name shown in column J. All records with GEOs already present should be bypassed. The code I built for this overwrites every record, unfortunately:

For z = 1 To LR
    x = Application.VLookup(Cells(z, "J"), Sheets("MasterTerritoryList").Columns("A:F"), 6, False)
    If Not (IsError(x)) Then
       Cells(z, "E").Value = x
    End If
Next z

Can someone help me out by showing me how to read the data in column E and replace only those values that equal "-"?

Many thanks!!

1 Answers
Related