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

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

wigi

Well-known Member
Joined
Jul 10, 2006
Messages
7,964
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
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

wigi

Well-known Member
Joined
Jul 10, 2006
Messages
7,964
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
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

BThomsen

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

wigi

Well-known Member
Joined
Jul 10, 2006
Messages
7,964
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
You're welcome, thank you for the feedback.
 
Upvote 0

Forum statistics

Threads
1,187,175
Messages
5,962,044
Members
438,578
Latest member
MrJimC

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
Top