作者:绿色风
分类:
时间:2022-08-18
浏览:126
楼主 xmyjk |
Q:如何使用用VBA+ADO+SQL完成手工录入数据和电子口岸数据的比对?
A:- Option Explicit
- Sub test()
- Dim cnn As Object, sql As String, BT As String, rcd As Object, i As Integer, j As Integer
- Application.ScreenUpdating = False
- [a1].CurrentRegion.Clear
- Set cnn = CreateObject("ADODB.Connection")
- Set rcd = CreateObject("ADODB.recordset")
- cnn.Open "provider=microsoft.jet.oledb.4.0;extended properties='excel 8.0;imex=1';data source=" & ThisWorkbook.FullName
- sql = "select a.[sb_ym] as 月份, a.[sb_no] as 序号, a.[inv_no] as 出口**号, (a.[bgd_no]-b.[bgd_no1]) as 报关单号比对, (a.[lj_date] - b.[lj_date]) as 出口日期对比, (a.[hxd_no] - b.[hxd_no]) as 核销单号对比 ,(a.cmcode - b.cmcode) as 商品代码对比 , (a.qnt - b.[fd_qnt]) as 出口数量对比 , IIF(a.bicode = b.[yb_bz] , 0 , ""错误"") as 币种对比, (a.[yb_amt] - b.[yb_amt]) as 金额对比 , IIF(ucase(a.[hgdjc_no]) = ucase(b.[hgdjc_no]) OR (a.[hgdjc_no] = """" and isnull(b.[hgdjc_no])), 0 , ""错误"") as 进料加工手册号对比 FROM [后台退税明细数据$] as a left join [电子口岸数据$] as b on a.[bgd_no] = b.[bgd_no1] order by a.[sb_no]"
- rcd.Open sql, cnn
- For i = 1 To rcd.Fields.Count
- Cells(1, i) = rcd.Fields(i - 1).Name
- Next
- [A2].CopyFromRecordset rcd
- rcd.Close: Set rcd = Nothing
- cnn.Close: Set cnn = Nothing
- Application.ScreenUpdating = True
- MsgBox "Ok"
- End Sub
出口退税比对模版.rar |
2楼 yjzstar |
跟师傅学习! |
3楼 eliane_lei |
进来学习,谢谢分享 |
免责声明
有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素,
经与ExcelTip.Net站长Apolloh商议并征得其同意,
现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示,
供有需要的人士查询使用,也慰缅曾经的论坛时代。
所示各个帖子的原作者如对版权有异议,
可与本人沟通提出,或于本站点留言,我们会尽快处理。
在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一