|
首先感谢群里的大神赵老师,以下代码就是完全复制过来的。然后我只是把SQL语句内的字段改了,如果条数小就不会报错,但如果条数太多就会报错了,然后我又用赵老师的实例往里面加了10000多条数据发现又不会报错,但我改成我对应的表头和字段后就会报错,困扰了好久了。希望大神出手相救。 附件太大就不上传了,截图
Private Sub CommandButton2_Click()
Dim cnn As New ADODB.Connection
Dim sql As String
Dim arr, brr(), crr(), i&, r, d As Object
Set d = CreateObject("scripting.dictionary")
arr = Range("A2:A" & Range("A65500").End(xlUp).Row)
For i = 1 To UBound(arr)
d(arr(i, 1)) = i
Next
ReDim brr(1 To i - 1, 1 To 1)
ReDim crr(1 To i - 1, 1 To 1)
cnn.Open "provider=microsoft.ace.oledb.12.0;data source=G:\售后表格\每日发货清单表\发货表(1).accdb"
sql = "select x.订单号,商家编码 from [Excel 8.0;Database=" & ThisWorkbook.FullName & ";].[Sheet1$A1:A" & Range("A65500").End(xlUp).Row & "] x left join 订单明细1 y on x.订单号=y.订单号"
arr = cnn.Execute(sql).GetRows
For i = 0 To UBound(arr, 1)
r = d(arr(0, i))
brr(r, 1) = arr(1, i)
Next
Range("B2").Resize(UBound(brr)) = brr
cnn.Close
Set cnn = Nothing
End Sub
|
|