mardi 5 janvier 2021

VBA: How to enter a value according to another value in the same row but different column

Can you please help me figure out what is the way to enter a value to a cell in one column according to a value in a different column but the same row?

let's say I don't know where is the column but I do know what is the Header name and I know how to find it and declare it as a range.

  • Input:

Input:

  • Output:

Output

So far I tried:

For i = 2 To numOfDataRows
    If ((RngB.Cells(i, Fruit_address).Value = "Banana") Or (RngB.Cells(i, 
        Fruit_address).Value = "Lemon")) Then
        Rng12.Cells(i, Color_address).Value = "Yellow"
    End If
Next i

RngB is my Range for the fruits column. not necessarily column B. Rng12 is my Range for the Colors column. not necessarily column G.

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire