第一个问题,需用到辅助区域([空缺记录$a11:b25]),该辅助区域用于存放 所有AA、BB应该造访的任务列表,代码如下: Sub yy1() With Worksheets("空缺记录") Set CNN = CreateObject("adodb.connection") CNN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;hdr=yes;';Data Source=" & ThisWorkbook.FullName .Range("d2:e1000").ClearContents Sql = "select name,id FROM [空缺记录$a1:b10] group by name,id union all select name,id FROM [空缺记录$a11:b25]" Sql = "select name,id from (" & Sql & ") group by name,id having count(id)=1" .Range("d2").CopyFromRecordset CNN.Execute(Sql) End With End Sub |