以下是引用烟雨厦江南在2008-9-2 11:24:29的发言: 楼上的兄弟,能不能做个附件发上来学习一下 Sub fig() Dim arr() 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 r = .Range("a65536").End(xlUp).Row For i = 12 To 18 j = j + 1 ReDim Preserve arr(1 To j) arr(j) = "select " & i & " as vv from [空缺记录$a1:b10] " Next Sql = Join(arr, " union ") ' MsgBox Sql Sql = "select distinct aa.name,bb.vv from [空缺记录$a1:b10] aa ,(" & Sql & ") bb where len(aa.name)>0 and aa.name&bb.vv not in (select name&id from [空缺记录$a1:b10] where id>0) " .Range("d2").CopyFromRecordset CNN.Execute(Sql) End With End Sub
[此贴子已经被作者于2008-9-2 13:14:00编辑过] |