MATCH Value from Two Columns VBA

dskribow

New Member
Joined
Nov 21, 2015
Messages
12
Hi Everyone,

Here's what I have:

ABCD
1CustNameCustIDFNameLName
2Jane Dooey1JaneDoe
32JohnDooey
43JohnDoe
54JaneDooey

<tbody>
</tbody>


Here's what I'm trying to do: In VBA, get the CustID that matches the CustName.

Here's what I've got so far:
Code:
[COLOR=#333333]WorksheetFunction.Index(Sheet2.Range("b2:d5"), WorksheetFunction.Match(Sheet2.Range("a2"), Sheet2.Range("c2:c5") & " " & Sheet2.Range("d2:d5"), 0), 1)[/COLOR]

I've also tried to get this to work, to no avail:
Code:
[COLOR=#333333]WorksheetFunction.Index(Sheet2.Range("b2:d5"), WorksheetFunction.Match(Sheet2.Range("a2"), WoksheetFunction.Index(Sheet2.Range("c2:c5") & " " & Sheet2.Range("d2:d5"),) 0), 1)[/COLOR]

How can I do this/what am I doing wrong? I know that the worksheet version of the first code only works asan array formula in a worksheet, but the second one works just fine as a regular formula.


All advice is greatly appreciated.

Thanks.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
You could try implementing a For Each / Next loop...

Code:
Sub CustID()

Dim r As Range
Dim LastRow As Long

LastRow = Cells(Rows.Count, "C").End(xlUp).Row
For Each r In Range("C2:C" & LastRow)
    If Range("A2").Value = r & " " & r.Offset(0, 1) Then MsgBox r.Offset(0, -1)
Next r

End Sub

Cheers,

tonyyy
 
Upvote 0

Forum statistics

Threads
1,215,787
Messages
6,126,897
Members
449,347
Latest member
Macro_learner

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