Solved

Match Data

Posted on 2011-02-21
17
769 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
Comment Utility
Like this?

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

Author Comment

by:Cartillo
Comment Utility
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
Comment Utility
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
 
LVL 24

Expert Comment

by:StephenJR
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
How long did the first method take?

Hm, dictionary could be an option, will post back.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:Cartillo
Comment Utility
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
Comment Utility
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
Comment Utility
Hi,

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

Expert Comment

by:StephenJR
Comment Utility
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
Comment Utility
But can you post a workbook?
0
 

Author Comment

by:Cartillo
Comment Utility
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
Comment Utility
Hi StephenJR,

Thanks for the great help
0
 
LVL 24

Expert Comment

by:StephenJR
Comment Utility
Thanks Cartillo. Interesting to get feedback on the times.
0
 

Author Comment

by:Cartillo
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now