- ©«¤l
- 354
- ¥DÃD
- 5
- ºëµØ
- 0
- ¿n¤À
- 387
- ÂI¦W
- 0
- §@·~¨t²Î
- windows7
- ³nÅ骩¥»
- vba,vb,excel2007
- ¾\ŪÅv
- 20
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2017-1-8
- ³Ì«áµn¿ý
- 2024-8-2
|
¦^´_ 1# ssooi
¨âºØ¼gªk ¦Û¤v¬D¤@Ó
Sub t1()
o = Split("Provider=Microsoft.,,.0;Extended Properties=Excel ,,.0;Data Source=" & ThisWorkbook.FullName, ",")
Set cn = CreateObject("adodb.connection"): If Application.Version > 12 Then o(1) = "ACE.OLEDB.12": _
o(3) = 12: cn.Open Join(o, "") Else o(1) = "Jet.OLEDB.4": o(3) = 8: cn.Open Join(o, "")
q = "SELECT a.§Ç¸¹, a.®Éµ{, a.µP¤l FROM [¤u§@ªí2$A1:C] as a "
q = q & "WHERE EXISTS ( SELECT 1 FROM [¤u§@ªí2$A1:C] AS b "
q = q & " WHERE b.§Ç¸¹ = a.§Ç¸¹ AND b.µP¤l = a.µP¤l "
q = q & " GROUP BY b.§Ç¸¹, b.µP¤l HAVING COUNT(*) = 1)"
[G:J].ClearContents: [G1].CopyFromRecordset cn.Execute(q)
End Sub
Sub t2()
o = Split("Provider=Microsoft.,,.0;Extended Properties=Excel ,,.0;Data Source=" & ThisWorkbook.FullName, ",")
Set cn = CreateObject("adodb.connection"): If Application.Version > 12 Then o(1) = "ACE.OLEDB.12": _
o(3) = 12: cn.Open Join(o, "") Else o(1) = "Jet.OLEDB.4": o(3) = 8: cn.Open Join(o, "")
q = "SELECT a.§Ç¸¹, a.®Éµ{, a.µP¤l FROM [¤u§@ªí2$A1:C] AS a "
q = q & "WHERE ( SELECT COUNT(*) FROM [¤u§@ªí2$A1:C] AS b "
q = q & " WHERE b.§Ç¸¹ = a.§Ç¸¹ AND b.µP¤l = a.µP¤l) = 1"
[G:J].ClearContents: [G1].CopyFromRecordset cn.Execute(q)
End Sub |
-
-
TEST.zip
(15.54 KB)
|