Case- and character sensitive match and count with VBA

lopiteaux

Board Regular
Joined
Jun 8, 2011
Messages
77
Hi,

I need to compare 2 datasets, both with ~20k records, and determine whether a record in dataset A is present in dataset B.

The keys I need to compare need to take into account:
- case sensitivity (the keys are only unique when this distinction is made);
- wildcards (the keys can contain *, ?, ~, &, $, <, etc.)


I can accomplish the task using an exact match lookup (below), but the calculation time is ~10-15mins. Is there a better and faster way to do this via VBA?

{=INDEX(data_column,MATCH(TRUE,EXACT(value,lookup_column))}

Cheers,
l.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,729
Office Version
  1. 365
Platform
  1. Windows
Could you show us a sample of your data,, indicating what column/s to look in?
Also what do you want to happen if a match is found?
 

lopiteaux

Board Regular
Joined
Jun 8, 2011
Messages
77
A sample value is "@$E109*201|RTS22" - unfortunately I cannot share a sample as the data is highly confidential.

I need to return the row number of the MATCH, in the same way that a traditional MATCH works. I'm having to expand the MATCH to include the EXACT function given the special characters and case sensitivity.
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,979
Office Version
  1. 2016
Platform
  1. Windows
I need to compare 2 datasets, both with ~20k records, and determine whether a record in dataset A is present in dataset B.
Where are your two data sets located (sheet name or names, columns starting row)?

Where should the output go (next column)?
 

lopiteaux

Board Regular
Joined
Jun 8, 2011
Messages
77

ADVERTISEMENT

Where are your two data sets located (sheet name or names, columns starting row)?

Where should the output go (next column)?

The structure is as follows:
- Lookup values in D2:D20001 on sheet 'baseline';
- MATCH range in C2:C20001 on sheet 'report';
- INDEX range in E2:E20001 on sheet 'report';
- Response from INDEX/MATCH in E2:E20001 on sheet 'baseline';

Apologies for being vague!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,729
Office Version
  1. 365
Platform
  1. Windows
Is this what your after
Code:
Sub CompareCopy()

   Dim Valu As String
   Dim Cl As Range
   Dim BaseWs As Worksheet
   Dim RepWs As Worksheet
   
   Set BaseWs = Sheets("Test")
   Set RepWs = Sheets("SBD")
   With CreateObject("scripting.dictionary")
      For Each Cl In RepWs.Range("C2", RepWs.Range("C" & Rows.Count).End(xlUp))
         If Not .exists(Cl.Value) Then .Add Cl.Value, Cl.Offset(, 2).Value
      Next Cl
      For Each Cl In BaseWs.Range("D2", BaseWs.Range("D" & Rows.Count).End(xlUp))
         If .exists(Cl.Value) Then Cl.Offset(, 1).Value = .Item(Cl.Value)
      Next Cl
   End With

End Sub
 

lopiteaux

Board Regular
Joined
Jun 8, 2011
Messages
77
Thanks Fluff, that's exactly what I needed. You've brought it down to just over a second!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,729
Office Version
  1. 365
Platform
  1. Windows
Glad we could help & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,129,930
Messages
5,639,054
Members
417,067
Latest member
rohitbabshet

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
Top