|
本帖最后由 心电感应 于 2018-8-29 17:49 编辑
我现在有三列数据,要根据A列分组,每一列数据的个数不同。我曾经问过类似的问题(但是那次分组变量是数字),所以按照大神的方法自己改了之前的代码,以下,然后运行不成功
有别的方法可以解决也行。谢谢大家的帮助
- Sub 宏1()
-
-
-
- Dim conn As Object
- Dim sql As String, PathStr As String
- PathStr = ThisWorkbook.FullName
- Set conn = CreateObject("ADODB.Connection")
- Select Case Application.Version * 1
- Case Is <= 11
- conn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0;Extended Properties=excel 8.0;Data source=" & PathStr
- Case Is >= 12
- conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & PathStr & ";Extended Properties=""Excel 12.0;HDR=YES"";"""
- End Select
- conn.Open
- myrow = Sheet1.Range("A65536").End(xlUp).Row
- For Each i In Sheet2.Range("A2:A68")
- sql = "select * from [Sheet1$A1:c" & myrow & "] where 曲线名称=" & i
- Sheet1.Range("XFD2").End(xlToLeft).Offset(0, 5).CopyFromRecordset conn.Execute(sql)
- Next
- conn.Close
-
-
- End Sub
复制代码
|
|