Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Match Data

Posted on 2011-02-21
17
772 Views
Last Modified: 2012-05-11
Hi Experts,

I would like to request Experts help create a macro to compare data at “List” Sheet (Column B) with data at “Database” sheet (Column A to F). If data at cell “List” sheet is matched, cell at column C (List sheet) will be updated as ‘Y”, if not the cell well be updated with “N”. I have created a sample data at column C in “List” sheet for Experts to get better view. Hope Experts will to create this feature.



DataCheck.xls
0
Comment
Question by:Cartillo
  • 9
  • 8
17 Comments
 
LVL 24

Expert Comment

by:StephenJR
ID: 34941455
Like this?

=IF(COUNTIF(Database!$A$2:$F$22,B2)>0,"Y","N")
0
 

Author Comment

by:Cartillo
ID: 34941504
Hi,

Is that possible to get this in script? I have more than 700,000 data that need to crosscheck and also other  macro that I would like to run it together. Hope you will consider.
0
 
LVL 24

Expert Comment

by:StephenJR
ID: 34941521
So you don't want the formulae left there?
Sub x()

Dim r As Range

Set r = Sheets("Database").Range("A1").CurrentRegion

With Sheets("List")
    With .Range("C2", .Range("C" & Rows.Count).End(xlUp))
        .Formula = "=IF(COUNTIF(Database!" & r.Address & ",B2)>0,""Y"",""N"")"
        .Value = .Value
    End With
End With

End Sub

Open in new window

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 24

Expert Comment

by:StephenJR
ID: 34941537
Just noticed you have a lot of data so if this is slow we can find ways to speed it up.
0
 

Author Comment

by:Cartillo
ID: 34941602
Hi StephenJR,

You’re right. At present I have 789,000 data at Database sheet , I need to compare with at least 130,000 data at List sheet. Hope you can help to speedup the whole process.
0
 
LVL 24

Expert Comment

by:StephenJR
ID: 34941631
Cartillo - see if this is any quicker:
Sub x()
  
Dim rFind As Range, r As Range, rData As Range

Application.ScreenUpdating = False

Set rData = Sheets("Database").Range("A1").CurrentRegion

With Sheets("List")
    For Each r In .Range("B2", .Range("B" & Rows.Count).End(xlUp))
        Set rFind = rData.Find(What:=r, LookAt:=xlWhole, MatchCase:=False, SearchFormat:=False)
        If rFind Is Nothing Then
            r.Offset(, 1) = "N"
        Else
            r.Offset(, 1) = "Y"
        End If
    Next r
End With
     
Application.ScreenUpdating = True
     
End Sub

Open in new window

0
 

Author Comment

by:Cartillo
ID: 34941677
Hi,

Its took more than 5 minutes for 500 data (List sheet) to be compared with 700,000 data at “Database” sheet. Is that possible for us to use  “scripting.dictionary” method to speed up the process?
0
 
LVL 24

Expert Comment

by:StephenJR
ID: 34941693
How long did the first method take?

Hm, dictionary could be an option, will post back.
0
 

Author Comment

by:Cartillo
ID: 34941715
Hi,

It takes almost 7minutes to compare 500 data with 700,000 data at Database sheet.
0
 
LVL 24

Accepted Solution

by:
StephenJR earned 500 total points
ID: 34941767
Let's see if this speeds things up:
Sub x()
  
Dim oDic As Object, vData As Variant, i As Long, v, vOut(), j As Long

Set oDic = CreateObject("Scripting.Dictionary")
vData = Sheets("Database").Range("A1").CurrentRegion.Value
v = Sheets("List").Range("B2", Sheets("List").Range("B" & Rows.Count).End(xlUp))
ReDim vOut(1 To UBound(v, 1))

With oDic
    For j = LBound(vData, 2) To UBound(vData, 2)
        For i = LBound(vData, 1) To UBound(vData, 1)
            If Not IsEmpty(vData(i, j)) And Not .Exists(vData(i, j)) Then
                .Add vData(i, j), vData(i, j)
            End If
        Next i
    Next j
    For i = LBound(v, 1) To UBound(v, 1)
        If .Exists(v(i, 1)) Then
            vOut(i) = "Y"
        Else
            vOut(i) = "N"
        End If
    Next i
End With

Sheets("List").Range("C2").Resize(i - 1) = Application.Transpose(vOut)
   
End Sub

Open in new window

0
 

Author Comment

by:Cartillo
ID: 34941806
Hi,

Tested with the new solution, also takes around 6 minutes to accomplish 500 data.  
0
 
LVL 24

Expert Comment

by:StephenJR
ID: 34941817
I'm surprised that makes no difference. Temporarily out of ideas, perhaps others will have better ideas. You may just have to live with a few minutes.
0
 
LVL 24

Expert Comment

by:StephenJR
ID: 34941820
But can you post a workbook?
0
 

Author Comment

by:Cartillo
ID: 34948161
Hi StephenJR,

Sorry for the late reply. I've tested, and it just took <1min to crosscheck 560 data. Apology for the wrong update. I've accidentally select the old solution. Sorry for that.  
0
 

Author Closing Comment

by:Cartillo
ID: 34949133
Hi StephenJR,

Thanks for the great help
0
 
LVL 24

Expert Comment

by:StephenJR
ID: 34950339
Thanks Cartillo. Interesting to get feedback on the times.
0
 

Author Comment

by:Cartillo
ID: 34952689
Hi StephenJR,

Hope you will consider this request, need to modify your solution:

http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_26839039.html
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question