Hi,
I have created 3 different select statement (query) with different where clause critera. The first query wil start copying in row 2 until row 199. Second query will dump the data starting row 201 up to 399 while the last query will dump the data from row 401 up to 599. May I ask your help on how to do this in vba excel. your hlp is very much appreciated. thank you.
Dim sconnect As String
sconnect = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & datasource & ";" & _
"Extended Properties=""Excel 12.0;HDR=YES"";"
con.Open sconnect: DoEvents
Dim sqlstr As String
sqlstr = "SELECT * FROM [SAMPLE1$] e "
sqlstr = sqlstr & "WHERE e.Supplier = 'XXX' "
rec.Open sqlstr, con, 3, 1: DoEvents
Set wb = ThisWorkbook
With wb.Sheets("Template")
SourceRow = .Cells(.Rows.Count, "B").End(xlUp).Row
End With
Set ws = wb.Sheets("Original")
'clear data
ws.Range("A2:BK800").ClearContents
TargetRow = ws.Range("B" & ws.Rows.Count).End(xlUp).Row
'Evaluate the rows
varCount = rec.RecordCount
If varCount > 1 Then
With ws
' Need this portion to dump in row2
.Range("A" & .Rows.Count).End(xlUp).Offset(1, 0).CopyFromRecordset rec
End With
Else
MsgBox "Successfully updated XXX Supplier to Original Worksheet!", vbInformation
ActiveWorkbook.RefreshAll
Exit Sub
End If
Bookmarks