First I want to apologize if the answer to my question is overly simple as I am new to VBA. I am trying to write a code that will search what I put in the clipboard and return the location of the item in question.
THIS WORKS FOR A STATIC VALUE
Dim MyDataObj As New DataObject
Dim myVar As Variant
Dim srcRange As range
Selection.Copy
MyDataObj.GetFromClipboard
myVar = MyDataObj.GetText
Set srcRange = Worksheets("Sheet1").Columns("F").Find(what:="12556")
MsgBox "The previous occurrence is in cell " & srcRange.address
When i replace "12556" with myVal and step through and hover over myVal it correctly shows it's value as myVal=12556 but when i step through the msgbox code it breaks with a "Object variable or With block variable not set." I know I'm missing something probably very easy but I'm stuck. Any help would be appreciated.
THIS WORKS FOR A STATIC VALUE
Dim MyDataObj As New DataObject
Dim myVar As Variant
Dim srcRange As range
Selection.Copy
MyDataObj.GetFromClipboard
myVar = MyDataObj.GetText
Set srcRange = Worksheets("Sheet1").Columns("F").Find(what:="12556")
MsgBox "The previous occurrence is in cell " & srcRange.address
When i replace "12556" with myVal and step through and hover over myVal it correctly shows it's value as myVal=12556 but when i step through the msgbox code it breaks with a "Object variable or With block variable not set." I know I'm missing something probably very easy but I'm stuck. Any help would be appreciated.