Ok pessoal segue solução,
Private Sub Fornecedor_Click()
Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim sql As String
Set conn = New ADODB.Connection
With conn
'.Provider = "Microsoft.JET.OLEDB.4.0" ' versão excel 2003
.Provider = "Microsoft.ACE.OLEDB.12.0" ' versão excel 2007
.ConnectionString = "Data Source=" & ThisWorkbook.FullName & ";Extended Properties=Excel 8.0;"
.Open
End With
sql = "SELECT DISTINCT Fornecedor,Contrato FROM [Servico$]"
Set rst = New ADODB.Recordset
With rst
.ActiveConnection = conn
.Open sql, conn, adOpenDynamic, _
adLockBatchOptimistic
End With
Do While Not rst.EOF
If Not IsNull(rst(0).Value) Then
If Fornecedor.Text = rst!Fornecedor Then
Contrato.Text = rst!Contrato
End If
End If
rst.MoveNext
Loop
' Fecha o conjunto de registros.
Set rst = Nothing
' Fecha a conexão.
conn.Close
End Sub
Existem mil maneiras de preparar Neston. Invente a sua!
http://www.youtube.com/ExpressoExcel
Postado : 22/10/2012 11:54 am