Return list of integer values next string values
Question:
Answers:
I have two columns of data. The first column is a list of unique
integer values. The second column is a list of string values of which
some of the values duplicate. I want to write a brief macro (or cell
formula) that will return the integer value next to the string.
Integers Strings Ideal Printout
0 Bob 0
1 Joe 1,2
2 Joe 1,2
3 Susan 3,5
4 Sally 4
5 Susan 3,5
Sorry if the above is not clear. Having a hard time articulating
this. I am also happy if the printout is a column for each integer.Answers:
This works for me:
I used it like this:Public Function GETMATCHES(ByVal match As String, ByVal cells As Range, ByVal columnOffset As Integer) As String Dim result As String Dim cell As Range For Each cell In cells If cell.Value2 = match Then result = result & "," & cell.Offset(0, columnOffset).Value2 End If Next If Len(result) > 0 Then result = Right(result, Len(result) - 1) End If GETMATCHES = result End Function
=GETMATCHES(B2,$B$2:$B$7,-1)
Commentaires
Enregistrer un commentaire