问题
I have a data set:
ID Name Amount BID BID 2
1 Jack 100 1
1 John 200 *Blank*
2 Tony 300 2
How can I lookup the ID and where the ID is matching look at the BID and find the relating ID value where the ID value has been populated for the same ID. I want the value to appear in BID 2 which is in column 5.
IE John should have a BID of 1 as his ID is 1 like Jacks ID.
I have tried
=vlookup(A2,A2:C5,3,FALSE)
回答1:
I honestly don't know a way to do this through formula, but a VBA solution would look like this:
Sub FindTheValue()
Dim sht As Worksheet, lastrow As Long, i As Long, j As Long
Set sht = ThisWorkbook.Worksheets("Sheet1")
lastrow = sht.Cells(sht.Rows.Count, "C").End(xlUp).Row
For i = 1 To lastrow
If Range("Z" & i).Value = "" Then
For j = 1 To lastrow
If Range("C" & i).Value = Range("C" & j).Value And Range("Z" & j).Value <> "" Then
Range("AA" & i).Value = Range("Z" & j).Value
Exit For
End If
Next j
End If
Next i
End Sub
来源:https://stackoverflow.com/questions/49015763/lookup-function-for-matching-ids-and-then-populating-an-additional-value-vloo