?
Solved

Match Data

Posted on 2011-02-21
17
Medium Priority
?
775 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
[X]
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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

762 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