Hey all,
I've got a VBA code but I'm trying to configure it to my needs but every statement I try I fail.
I need to set an IF/WHERE ID number equals a row on my spreadsheet... I need to copy the whole row if the ID number is matched
Thanks in advance folks
I've got a VBA code but I'm trying to configure it to my needs but every statement I try I fail.
I need to set an IF/WHERE ID number equals a row on my spreadsheet... I need to copy the whole row if the ID number is matched
Thanks in advance folks
VBA Code:
'Add reference for Microsoft Activex Data Objects Library
Sub sbADO()
Dim sSQLQry As String
Dim ReturnArray
Dim Conn As New ADODB.Connection
Dim mrs As New ADODB.Recordset
Dim DBPath As String, sconnect As String
DBPath = ThisWorkbook.FullName
'You can provide the full path of your external file as shown below
'DBPath ="C:\InputData.xlsx"
sconnect = "Provider=MSDASQL.1;DSN=Excel Files;DBQ=" & DBPath & ";HDR=Yes';"
Conn.Open sconnect
[B] sSQLSting = "SELECT * From [DataSheet$] WHERE (ID = '1')" '[/B]
mrs.Open sSQLSting, Conn
'=>Load the Data into an array
'ReturnArray = mrs.GetRows
''OR''
'=>Paste the data into a sheet
ActiveSheet.Range("A2").CopyFromRecordset mrs
'Close Recordset
mrs.Close
'Close Connection
Conn.Close
End Sub