Mình có đoạn code sau nhờ mọi người sữa giùm
Hiện tại mình đã có insert into gán giá trị vào
Select distin lọc dữ liệu trùng
Mình đã sử dụng update nhưng không được
Làm sao mình xóa đi dữ liệu cũ và gán dữ liệu đã lọc trùng vào
Hoặc có cách nào chạy RemoveDuplicates không
Lưu ý 2 file nầy đang đóng, và code nằm ở file thứ 3
Sub LayData()
Dim strFileA As String, strFileB As String, rs
strFileA = Left(Application.StartupPath, Application.Search("User", Application.StartupPath) + 3) & "\Desktop\" & "FileNguon.xlsx"
strFileB = Left(Application.StartupPath, Application.Search("User", Application.StartupPath) + 3) & "\Desktop\" & "Filedulieu.xlsx"
Set Cn = CreateObject("ADODB.Connection")
With Cn
.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strFileB & ";Extended Properties=""Excel 12.0;HDR=No"""
.Execute ("Insert Into [dulieu$] Select * FROM[EXCEL 12.0;HDR=No;Database=" & strFileA & "].[$A2:AW]")
Set rs = .Execute("SELECT distinct * From [A2:AW] WHERE f1 is not Null")
.Execute ("Update [dulieu$] set [F1] =" & rs & "")
.Close
End With
Set Cn = Nothing
Set rs = Nothing
End Sub
Hiện tại mình đã có insert into gán giá trị vào
Select distin lọc dữ liệu trùng
Mình đã sử dụng update nhưng không được
Làm sao mình xóa đi dữ liệu cũ và gán dữ liệu đã lọc trùng vào
Hoặc có cách nào chạy RemoveDuplicates không
Lưu ý 2 file nầy đang đóng, và code nằm ở file thứ 3
Sub LayData()
Dim strFileA As String, strFileB As String, rs
strFileA = Left(Application.StartupPath, Application.Search("User", Application.StartupPath) + 3) & "\Desktop\" & "FileNguon.xlsx"
strFileB = Left(Application.StartupPath, Application.Search("User", Application.StartupPath) + 3) & "\Desktop\" & "Filedulieu.xlsx"
Set Cn = CreateObject("ADODB.Connection")
With Cn
.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strFileB & ";Extended Properties=""Excel 12.0;HDR=No"""
.Execute ("Insert Into [dulieu$] Select * FROM[EXCEL 12.0;HDR=No;Database=" & strFileA & "].[$A2:AW]")
Set rs = .Execute("SELECT distinct * From [A2:AW] WHERE f1 is not Null")
.Execute ("Update [dulieu$] set [F1] =" & rs & "")
.Close
End With
Set Cn = Nothing
Set rs = Nothing
End Sub