|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub test1()
Dim Conn As Object, rs As Object, SQL As String, ar
Set Conn = CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.FullName
Worksheets(1).Activate
Range("D4") = vbNullString
SQL = "SELECT DISTINCT [Work ID] FROM [" & Worksheets(2).Name & "$] WHERE [Customer PO#]='" & Range("G4").Value & "'"
Set rs = Conn.Execute(SQL)
If rs.EOF And rs.bof Then
MsgBox "Customer PO# [" & Range("G4").Value & "] not found!", vbInformation
Else
ar = WorksheetFunction.Transpose(WorksheetFunction.Transpose(rs.GetRows))
Range("D4") = Join(ar, ","): Beep
End If
Set rs = Nothing
Conn.Close
Set Conn = Nothing
End Sub |
评分
-
1
查看全部评分
-
|