Sub ssearch()
Dim dB As DAO.Database
Dim Rec As DAO.Recordset
Dim xsearch As String
Dim rng As Range, cell As Range
Set rng = Range("A2:A" & Cells(65536, "A").End(xlUp).Row)
For Each cell In rng
If (cell.Value <> "") Then
xsearch = "SELECT tblGreen.tblGreenSku FROM tblGreen Where tblgreen.tblSku=""" & cell.Value & """;"
Set dB = OpenDatabase("C:\DATA\MyGreen.mdb")
Set Rec = dB.OpenRecordset(xsearch)
cell.Offset(0, 2).CopyFromRecordset Rec
If (Trim(cell.Offset(0, 2).Value) = "") Then
cell.Offset(0, 2).Value = "NO GREEN"
End If
End If
Next cell
Rec.Close
dB.Close
Set Rec = Nothing
Set dB = Nothing
End Sub
|