Solved

Match Data

Posted on 2011-02-21
17
773 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

733 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