Forum Discussion
MicrosoftNewbie121
Jan 30, 2024Brass Contributor
MACRO VBA : Find ID in Sheet and Copy DATA from the second Sheet
Hello, could you please help me with this MACRO VBA ? i would like to find IDs from Sheet "Updating" and if the same ID exists in Sheet "Update" i would like to copy data corresponding to the ID fr...
peiyezhu
Jan 30, 2024Bronze Contributor
Set Conn = CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Ace.OLEDB.12.0;Extended Properties='Excel 12.0; HDR=NO;IMEX=3';Data Source=" & ThisWorkbook.FullName
Set Rst=CreateObject("ADODB.Recordset")
sql="update [Updated$a3:j] as a inner join [updating$a2:j] as b on a.f2=b.f2 set a.f5=b.f5,a.f6=b.f6,a.f7=b.f7,a.f8=b.f8"
Conn.Execute(sql)
'sql="select * from [Updated$A3:j]"
'set Rst=Conn.Execute(sql)
' sql="select f2 from [Updating$A2:j]"
'sql="select f2 from [Updated$A3:j]"
'Conn.Execute(sql)
'ActiveCell.CopyFromRecordset Rst
MicrosoftNewbie121
Jan 30, 2024Brass Contributor
peiyezhu 谢谢, Thank you but data is missing and it's mixed Data in "Field" Column should appear in Owner 2 ^^
- peiyezhuJan 30, 2024Bronze ContributorYou are welcome.
try this way:
sql="update [Updated$a3:j] as a inner join [updating$a2:j] as b on a.f2=b.f2 set a.f5=b.f5,a.f6=b.f6,a.f7=b.f7,a.f10=b.f8"