|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
我安装的是Excel2016版,写了一段代码查询数据。发现当我数据源总行数小于65535时运行正常,但是超过这个行数就会报错,不知道错误原因在哪?望大神指导。代码如下:
- Sub 查询()
- Dim Rng&, T%, k%
- Dim cnn As Object
- Dim SQL$, Str$
- Set cnn = CreateObject("adodb.connection")
- cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;Hdr=No';Data Source=" & _
- ThisWorkbook.FullName
- Rng = ThisWorkbook.Sheets("财务数据").Range("A1").End(xlDown).Row
- k = Cells(7, 5)
- If Cells(8, 5).Value Like "所有" Then
- Str = ""
- Else
- Str = "where f43 like '" & Cells(8, 5).Value & "'"
- End If
- SQL = "transform sum(f" & k & ") select f1 from [财务数据$A2:BD" & Rng & "] " & Str & " group by f1 pivot f2"
- Range("D17").CopyFromRecordset cnn.Execute(SQL)
- End Sub
复制代码
|
|