Will Match Function Work With A Worksheet Connected Via An ADODB Connection?

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am playing with this concept to access data from a closed workbook. Because I am unfamiliar with this, and simply experimenting, I'm unsure if what I am trying to do (find the match of a value in the worksheet of the closed workbook) is even possible with this method. If it's possible, I'm clearly not understanding the contecxt well enough for which my code is incorrect. The line in red is leaving me with an object required error. I assume rs.source isn't an object.
Rich (BB code):
Sub StaffOnChange()
    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim staffPath As String
    Dim staffFile
    Dim staffOpn As String
    Dim stfRow As Long
    
    Set wsHold = Application.ThisWorkbook.Worksheets("Hold")
    
    staffPath = "D:\WSOP 2020\SupportData\"
    staffFile = wsHold.Range("N1")
    staffOpn = staffPath & staffFile
    Set cn = New ADODB.Connection
    
    cn.ConnectionString = _
        "Provider=Microsoft.ACE.OLEDB.12.0;" & _
        "Data Source=" & staffOpn & ".xlsm;" & _
        "Extended Properties='Excel 12.0 Macro;HDR=YES';"
    cn.Open
    Set rs = New ADODB.Recordset
    rs.ActiveConnection = cn
    rs.Source = "SELECT * from [MASTER$]"
    rs.Open
    stfRow = Application.WorksheetFunction.Match(wsHold.Range("C3"), rs.Source.Columns(1), 0)
    rs.Close
    cn.Close
End Sub

The hope is that if I can get the row (match value) from the data in the closed workbook, I can populate a series of cells in the active workbook without having to rely on 167 different vlookup formulae.

Looking for input from the good folk here to advise whether I'm on the wrong path to success with this method.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top