-
-
Try this. If it works as you want, it is much faster than yours as written ATT.
[vba]Option Explicit
Sub VbLookUp()
Dim UPCItem As String 'item is a keyword. Never use keywords as names.
Dim Desc As String
Dim UPC As Long
Dim ws As Worksheet
Dim wd As Worksheet
Dim Found As Range
Set ws = ActiveWorkbook.Sheets("Capture")
Set wd = ActiveWorkbook.Sheets("Catalog")
''''Get UPC
UPC = CLng(ws.OLEObjects("TxtUPC").Object.Value)
'''Find Cell with UPC
Set Found = wd.Range("B2:B800").Find(UPC, LookIn:=xlValues)
''''Check needed values and set variable as indicated
If Found Is Nothing Then
UPCItem = "Not Found"
Desc = "Not Found"
Else
If Found.Offset(0, 1).Value <> "" Then _
UPCtem = CStr(Found.Offset(0, 1).Value)
If Found.Offset(0, 2).Value <> "" Then
Desc = CStr(Found.Offset(0, 2).Value)
Else
ws.Shapes("CmdAdd").Visible = True 'I'm not sure this belongs here, but,
're program flow, this is where it was.
End If
End If
''''Read Variables into OLEObjects
ws.OLEObjects("TxtItem").Object.Value = UPCItem
ws.OLEObjects("TxtDesc").Object.Value = Desc
'Recommend place it here
'ws.Shapes("CmdAdd").Visible = _
(Desc = "Not Found") _
Or _
(UPCItem = "Not Found")
'I set it true for both
End Sub
[/vba]
-
WOW SamT, that seems to work.
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules