vbaexcelms-accessms-access-2007

vLookup ~50K records against a database of over 1 million keywords


I need a macro to do a vLookup on a sheet (~50K records) against a database of over one million keywords.

Will the process become faster if I use MS Access 2007 as the database to vLookup it?
Is there any other way to make this process faster by using a different database etc.?


Solution

  • If you already have these keywords stored in Excel, it is worth looking a ADO to read the words as a table. This is a quick example, but it is also simple enough to join the list of words to be looked up in an INNER or LEFT JOIN and find the missing and matching words. This can also be done if the keywords are stored externally in a database by using in-line connection strings.

    Dim cn As Object
    Dim rs As Object
    Dim strFile As String
    Dim strCon As String
    Dim strSQL As String
    Dim s As String
    Dim i As Integer, j As Integer
    
    ''This is not the best way to refer to the workbook
    ''you want, but it is very convenient for notes
    ''It is probably best to use the name of the workbook.
    
    strFile = ActiveWorkbook.FullName
    
    ''Note that if HDR=No, F1,F2 etc are used for column names,
    ''if HDR=Yes, the names in the first row of the range
    ''can be used. 
    ''
    ''This is the ACE connection string, you can get more
    ''here : http://www.connectionstrings.com/excel
    
    strCon = "Provider=Microsoft.Jet.OLEDB.12.0;Data Source=" & strFile _
        & ";Extended Properties=""Excel 12.0;HDR=Yes;IMEX=1"";"
    
    ''Late binding, so no reference is needed
    
    Set cn = CreateObject("ADODB.Connection")
    Set rs = CreateObject("ADODB.Recordset")
    
    cn.Open strCon
    
    ''Watch out for case sensitivity
    strSQL = "SELECT [ColumnName] " _
           & "FROM [Sheet1$] " _
           & "WHERE ColumnName ='" & strWord & "'"
    
    rs.Open strSQL, cn, 3, 3
    
    MsgBox rs.GetString
    
    ''Tidy up
    rs.Close
    Set rs=Nothing
    cn.Close
    Set cn=Nothing