Using "Find" with clipboard VBA

BThomsen

New Member
Joined
Jan 23, 2014
Messages
2
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.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Why not simply:

Code:
Sub wigi()

    MsgBox "The previous occurrence is in cell " & Sheet1.Columns("F").Find(what:=ActiveCell.Value).Address

End Sub
 
Upvote 0
PS: Welcome to MrExcel.
It seems that you are new here ;)

Can you please use
Code:
 tags when you paste code on the forum?
Code tags format the code making it easier to read and hence follow the logic of the code.


You can use [CODE] tags in this way: 


Add the word [color=blue][b][PLAIN][code=rich][/PLAIN][/B][/color] before the first line of code, and
add the word [color=blue][b][PLAIN]
[/PLAIN][/B][/color] after the last line of code.


Or: you could use the "#" icon when changing / composing a message in the Advanced editing screen.


Thanks for your consideration.
 
Upvote 0
Thanks Wigi I obviously was making that way to hard... Thank you for the quick response. Yes I am new and I will definitely take your advice on posting... thanks again!
 
Upvote 0
You're welcome, thank you for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,812
Messages
6,121,704
Members
449,048
Latest member
81jamesacct

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top