The code below is a combination of HLOOKUP and VLOOKUP. Instead of entering the number of the row/column in the range you can enter a value from the upper row or left column.
When one of the values you search on is not found a zero is returned.
Code
Public Function VHLOOKUP(SearchRange As Range, SearchVertical As String, SearchHorizontal As String) As Variant
Dim SearchColumn As Variant
Dim SearchRow As Variant
Dim ColumnCount As Integer
Dim RowCount As Integer
Dim FindColumn As Integer
Dim FindRow As Integer
ColumnCount = 0
RowCount = 0
For Each SearchColumn In SearchRange.Columns
ColumnCount = ColumnCount + 1
If UCase(SearchColumn.Columns.Cells(1, 1).Value) = UCase(SearchHorizontal) Then
FindColumn = ColumnCount
End If
Next SearchColumn
For Each SearchRow In SearchRange.Rows
RowCount = RowCount + 1
If UCase(SearchRow.Rows.Cells(1, 1).Value) = UCase(SearchVertical) Then
FindRow = RowCount
End If
Next SearchRow
If FindColumn = 0 Or FindRow = 0 Then
VHLOOKUP = 0
Else
VHLOOKUP = SearchRange.Cells(FindRow, FindColumn).Value
End If
End Function
Display More
Copy this code to a VBA module to create this user defined function.