作者:笨雄不笨 | 来源:互联网 | 2023-09-23 12:32
Sub 按钮1_单击()
Set mycn = CreateObject(" nnection")
mycn代码在附件。。Open "Provider=Microsoft。Jet。OLEDB。4。0;Extended Properties='Excel 8。
0;hdr=yes;imex=1';Data Source=" & ThisWorkbook代码在附件。。FullName
Sql = "select max(ff) from (select(count(a))as ff from [sheet1$j1:j65536] group by a) "
mymax = mycn代码在附件。。
Execute(Sql)代码在附件。。getrows()(0, 0)
Sql1 = "select * from (select a,c,d,B代码在附件。。k as yourcount from [sheet1$j1:m65536] as A inner join (select a as a1,count(a) as k from [sheet1$j1:j65536] group by a) as B on A。
a=B代码在附件。。a1) where yourcount=" & mymax
Columns("q:s")代码在附件。。Clear
[q2]代码在附件。。CopyFromRecordset mycn。Execute(Sql1)
Columns("t:t")代码在附件。。
Delete '出现的次数,如果要,就不要删除这一列
mycn代码在附件。。Close
Set mycn = Nothing
End Sub
a,b,c,d的列标题变换了,代码中也要跟着变换代码在附件。。
这是用了SQL的方法,当然用其它的循环方式,速度不是很理想的代码在附件。。