- ©«¤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
 
|
¥»©«³Ì«á¥Ñ singo1232001 ©ó 2023-3-1 09:05 ½s¿è
¦^´_ 1# willeddie
Sub TEST()
Set cn = CreateObject("adodb.connection")
C = ".0; Data Source=" & ThisWorkbook.FullName
Select Case Application.Version
Case Is < 12: cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8" & C
Case Else: cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12" & C: End Select
q = "select ¤é´Á,²£«~,sum(¼Æ¶q) as ¼Æ¶q from [¤u§@ªí2$a1:C] "
q = q & "group by ¤é´Á,²£«~ having ¤é´Á is not null "
With Sheets("¤u§@ªí2"): .Range("F:H").ClearContents
Set rs = cn.Execute(q)
For i = 0 To rs.Fields.Count - 1 '¨ú¼ÐÃD¡A¦pªG¤£n¥i¬Ù²¤
.Cells(1, i + 6) = rs.Fields(i).Name
Next
.Cells(2, 6).CopyFromRecordset rs : End With
End Sub |
|