|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 autumnalRain 于 2015-11-11 17:00 编辑
求助贴子,希望实现的效果是[查询$]表里"标题"栏有的数据,在[采集$]表中将其记录删掉.使用RECORDSET方法的GETROWS方法将记录集转为数组。因为其特殊性,需要再次转置才能COPY到单元格区域。但在解答过程中这一行却总是报错。Sheets("采集").Range("a2").Resize(UBound(arr, 2) + 1, UBound(arr, 1) + 1) = Application.Transpose(arr)没办法只能采用注释掉的部分才能得到正确结果。
错误类型、错误代码行见见图示:请老师们指导下这行代码究竟错在哪里?
- Sub TEST()
- Dim CONN As Object, rst As Object
- strconn = "provider=microsoft.ACE.OLEDB.12.0;extended properties='Excel 12.0;hdr=yes';data source=" & ThisWorkbook.FullName '2007及以上
- 'strconn = "provider=microsoft.JET.OLEDB.4.0;extended properties='Excel 8.0;hdr=yes';data source=" & ThisWorkbook.FullName'2003
- Sql = "select * from [采集$] where 标题 not in (select 标题 from [查询$C4:C17])"
- Set CONN = CreateObject("ADODB.CONNECTION")
- Set rst = CreateObject("ADODB.recordset")
- CONN.Open strconn
- rst.Open Sql, CONN, 3, 3
- arr = rst.getrows
- Sheets("采集").Cells.Value = ""
- For i = 1 To rst.Fields.Count
- Sheets("采集").Cells(1, i) = rst.Fields(i - 1).Name
- Next
- x = UBound(arr, 2) + 1: y = UBound(arr, 1) + 1
- Sheets("采集").Range("a2").Resize(UBound(arr, 2) + 1, UBound(arr, 1) + 1) = Application.Transpose(arr)
- 'Sheets("采集").Range("a2").Resize(UBound(arr, 1) + 1, UBound(arr, 2) + 1) = arr
- 'BRR = Application.Transpose(Sheets("采集").Range("a2").Resize(UBound(arr, 1) + 1, UBound(arr, 2) + 1))
- 'Sheets("采集").Range("a2").Resize(UBound(arr, 1) + 1, UBound(arr, 2) + 1) = ""
- 'Sheets("采集").Range("a2").Resize(UBound(arr, 2) + 1, UBound(arr, 1) + 1) = Brr
- End Sub
复制代码
|
|