Rajkumar_h
New Member
- Joined
- Oct 4, 2013
- Messages
- 20
Hi Expert,
I have three sheets of data using LEFT JOIN i am supposed to pull the required columns as result. This is the main motive.
With the help of this link
https://analystcave.com/excel-using-...on-excel-data/I have three sheets of data using LEFT JOIN i am supposed to pull the required columns as result. This is the main motive.
With the help of this link
i took the code which does connection to my excel sheets.
I need an experts help to fix my issue, here is the code for your reference.
I need an experts help to fix my issue, here is the code for your reference.
Code:
[LEFT][COLOR=#333333][FONT=monospace]Sub RunSELECT()
Dim cn As Object, rs As Object, output As String, sql As String
'---Connecting to the Data Source---
Set cn = CreateObject("ADODB.Connection")
With cn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.ConnectionString = "Data Source=" & ThisWorkbook.Path & "\" & ThisWorkbook.Name & ";" & "Extended Properties=""Excel 12.0 Xml;HDR=YES"";"
.Open
End With
'---Run the SQL SELECT Query---
sql = "SELECT [MainData$].[PO], [Invoice], [Customer_Number], [Sls_Amt], [Shipping_Location],[GLList$].[Date], [new_Amount], [POList$].[Date], [PO_No], [ST] FROM [MainData$] LEFT JOIN [GLList$] ON [MainData$].[WOD_PO]=[GLList$].[WOD_PO] LEFT JOIN [POList$] ON [MainData$].[WOD_PO]=[POList$].[WOD_PO]"
Set rs = cn.Execute(sql)
Sheets.Add(After:=Sheets(Sheets.Count)).Name = "Temp"
With Sheets("Temp").Range("A1")
Do
i = 0
For Each fld In rs.Fields
ActiveCell.Offset(0, i).Value = fld
i = i + 1
Next fld
rs.MoveNext
ActiveCell.Offset(1, 0).Select
Loop Until rs.EOF
End With
'---Clean up---
rs.Close
cn.Close
Set cn = Nothing
Set rs = Nothing
End Sub[/FONT][/COLOR][/LEFT]
Waiting for the reply from an expert
Regards,
Raj
<strike></strike>Regards,
Raj