A1/B1
John 74
Jane 68
..
..
Sub Sample()
Dim Dict As Dictionary
Set Dict = New Dictionary
With Dict
.CompareMode = vbBinaryCompare
For i = 1 To 4
.Add Cells(0 + i, 1), Cells(0 + i, 2)
Next i
End With
Debug.Print GetKey(Dict, "68")
Debug.Print GetValue(Dict, "Jane")
End Sub
Function GetKey(Dic As Dictionary, strItem As String) As String
Dim key As Variant
For Each key In Dic.Keys
If Dic.Item(key) = strItem Then
GetKey = CStr(key)
Exit Function
End If
Next
End Function
Function GetValue(Dic As Dictionary, strkey As String) As String
Dim key As Variant
For Each key In Dic.Keys
If key = strkey Then
GetValue = CStr(Dic.Item(key))
Exit Function
End If
Next
End Function
John 74
Jane 68
..
..
Sub Sample()
Dim Dict As Dictionary
Set Dict = New Dictionary
With Dict
.CompareMode = vbBinaryCompare
For i = 1 To 4
.Add Cells(0 + i, 1), Cells(0 + i, 2)
Next i
End With
Debug.Print GetKey(Dict, "68")
Debug.Print GetValue(Dict, "Jane")
End Sub
Function GetKey(Dic As Dictionary, strItem As String) As String
Dim key As Variant
For Each key In Dic.Keys
If Dic.Item(key) = strItem Then
GetKey = CStr(key)
Exit Function
End If
Next
End Function
Function GetValue(Dic As Dictionary, strkey As String) As String
Dim key As Variant
For Each key In Dic.Keys
If key = strkey Then
GetValue = CStr(Dic.Item(key))
Exit Function
End If
Next
End Function