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.
 

Some videos you may like

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
40,597
Office Version
365
Platform
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
35,904
Office Version
2010
Platform
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
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
40,597
Office Version
365
Platform
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
40,597
Office Version
365
Platform
Windows
Glad we could help & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,098,991
Messages
5,465,863
Members
406,451
Latest member
KARANDREA

This Week's Hot Topics

Top