+ Reply to Thread
Results 1 to 33 of 33

Get matching values using ADO from closed CSV file

Hybrid View

  1. #1
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,136

    Re: Get matching values using ADO from closed CSV file

    I'd guess no matches. Try this version which will output something either way:
    Sub LookUp_With_ADO()
    On Error Resume Next
    
    Const adOpenStatic = 3
    Const adLockOptimistic = 3
    Const adCmdText = &H1
    
    Set objConnection = CreateObject("ADODB.Connection")
    Set objrecordset = CreateObject("ADODB.Recordset")
    
    objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=D:\MyFiles\;" & _
            "Extended Properties = ""text; HDR=No "","
            
    With ActiveWorkbook
        For i = 2 To 11 'LastRow 'I'm not sure if for loop
            objrecordset.Open "Select [F2], [F3], [F4] FROM [Origin.csv] Where [F1] = '" & .Sheets(1).Cells(i, 1).Value & "'", _
            objConnection, adOpenStatic, adLockOptimistic, adCmdText
            If Not objrecordset.EOF Then
                .Sheets(1).Cells(i, 2).CopyFromRecordset objrecordset
            Else
                .sheets(1).cells(i, 2).value = "no match"
            End If
                objrecordset.Close
        Next i
    End With
    End Sub
    Everyone who confuses correlation and causation ends up dead.

  2. #2
    Forum Contributor
    Join Date
    06-07-2011
    Location
    Hnd
    MS-Off Ver
    Excel 2010
    Posts
    161

    Re: Get matching values using ADO from closed CSV file

    The same result. where is supposed to appear the pulled values? in active workbook right?

    If you see the attached files it must be 10 matches between result.xlsx and Origin.cvs.

    I'm confused why is not showing anything.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1