简体   繁体   中英

Formula to search rows for certain value and get corresponding cells

I'm trying to write a formula to search for all cells in a certain range (a certain range in a column), get the row id of any cell that matches a certain value, then get the values (of all the cells that matched) from a different column.

Something like:

    A     B
1   ABC   123
2   DEF   456
3   GHI   789
4   ABC   100

Now what I need is to look in A1:A4 for "ABC" which will return A1 and A4, and get the value of B1 and B4. I couldn't figure it out.

I know I can do this in VBA. But it won't update on changing like formulas do.

For i = 2 To Excel.WorksheetFunction.CountA(Range("A:A"))
    If Range("A" & i).Value = "ABC" Then
        MsgBox Range("B" & i).Value
    End If
Next I

This code find value "ABC" in "A" column and return "B" column row value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM