Solved

Match Data

Posted on 2011-02-21
17
771 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

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…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

803 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