程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Excel VBA / SQL联合会大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Excel VBA / SQL联合会?

开发过程中遇到Excel VBA / SQL联合会的问题如何解决?下面主要结合日常开发的经验,给出你关于Excel VBA / SQL联合会的解决方法建议,希望对你解决Excel VBA / SQL联合会有所启发或帮助;

您可以将ADO与Excel一起使用。

Dim cn As Object
Dim rs As Object
Dim strfile As String
Dim strCon As String
Dim strsql As String
Dim s As String
Dim i As Integer, j As Integer

''This is not the best way to refer to the workbook
''you want, but it is very conveIEnt for notes
''it is probably best to use the name of the workbook.

strfile = ActiveWorkbook.Fullname

''Note that if HDR=No, F1,F2 etc are used for column names,
''if HDR=Yes, the names in the first row of the range
''can be used. 
''This is the jet 4 connection String, you can get more
''here : http://www.connectionStrings.com/excel

strCon = "ProvIDer=Microsoft.jet.olEDB.4.0;Data source=" & strfile _
    & ";Extended PropertIEs=""Excel 8.0;HDR=Yes;IMEX=1"";"

''Late binding, so no reference is needed

Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")


cn.open strCon

''A sample query
strsql = "SELECT disTinct A, B C FROM ( " _
       & "SELECT A, B, C " _
       & "FROM [Sheet1$] " _
       & "union all " _
       & "SELECT A, B, C " _
       & "FROM [Sheet2$] ) As J "


''Open the recordset for more processing
''cursor Type: 3, adopenStatic
''Lock Type: 3, adLockOptimistic
''Not everything can be done with every cirsor type and 
''lock type. See http://www.w3schools.com/ado/met_rs_open.asp

rs.Open strsql, cn, 3, 3

''Write out the data to an empty sheet (no headers)
Worksheets("Sheet3").Cells(2, 1).copyFromrecordset RSS

解决方法

我正在尝试将2个不同工作表中的2个单独的列连接起来,以制成更长的列,然后可以从中使用Vlookup。

工作表1 A,B,C,D,E,F,G

工作表2 A,B,C,D,E,F,G

我想将工作表1中的B列和工作表2中的C列连接起来(联合),并找到新列表的DisTinct值。我已经为此工作了好几个星期。

谢谢

大佬总结

以上是大佬教程为你收集整理的Excel VBA / SQL联合会全部内容,希望文章能够帮你解决Excel VBA / SQL联合会所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:/SQL联合会