VLOOKUP Not Giving Result For Merged Cells

hrayani

Well-known Member
Joined
Jul 23, 2010
Messages
1,501
Office Version
  1. 2016
Platform
  1. Windows
Hello Friends,

Vlookup formula is not giving the desired results when some cells in the range are merged.

For Example.

A B
PO # Contract #

2) 301675
3) 301684 21130697
4) 301687

Column B2:B4 are merged cells

=vlookup(c1,a2:b4,2,0)

Now when i enter the po # 301675 in cell C1 the result shows contract # 21130697
But for the rest two PO # the result is showing 0 whereas it should show same
contract # for all 3 PO.

Hope anyone can provide a solution

Regards,

Humayun

 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
The best solution is to stop using merged cells. You couldnt use a straight vlookup for what you have there. The only cell with a value in column B is the topmost cell of the merged cells which is why one works but the others produce 0.
 
Upvote 0
yes u r right... but that's the last option....

is there any other friend who can look at it ??? or is it impossible for the vlookup to work for the merged cells ??
 
Last edited:
Upvote 0
You couldnt use a straight vlookup for what you have there. You could use a UDF but it wouldnt always be correct. Get rid of the merged cells. They arent ever necessary in spreadsheets.
 
Upvote 0
Heres a UDF. Bear in mind it wont always be displaying the correct results.

Code:
Function MERGEVLOOKUP(Lookup_Value As Range, Lookup_Table As Range, Column_Index_Number As Integer)

Dim myRow As Long, c As Range

If Column_Index_Number > Lookup_Table.Columns.Count Then
    MERGEVLOOKUP = CVErr(xlErrRef)
    Exit Function
End If

myRow = Application.Match(Lookup_Value.Value, Lookup_Table.Columns(1), 0)

If Not IsError(myRow) Then
    For Each c In Lookup_Table.Cells(1).Offset(myRow - 1, Column_Index_Number - 1).MergeArea
        If Len(c.Value) > 0 Then
            MERGEVLOOKUP = c.Value
            Exit For
        End If
    Next
Else
    MERGEVLOOKUP = CVErr(xlErrNA)
End If

End Function
 
Upvote 0

Forum statistics

Threads
1,214,973
Messages
6,122,534
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top