use vba to CtrlF from clipboard

himperson1

New Member
Joined
Jun 23, 2016
Messages
33
hello all. i am trying to filter out some duplicate data on my worksheet by copying a "uniqueness identifier" within the last cell of the worksheet and then pasting that into the CtrlF function of excel on a separate worksheet. here's what i've got so far but i am getting an error 424 "object required" when i reach the find function in the code. what am i missing?

Code:
    Dim DataObj As MSForms.DataObject
    Set DataObj = New MSForms.DataObject
    DataObj.GetFromClipboard


    Sheets("YTD").Select
    Range("A1").Select
    Selection.End(xlDown).Select
    Selection.End(xlToRight).Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1.Copy
    Sheets("Instructions For Use (2)").Select
    Range("A1").Select
    Cells.Find(What:=objData.GetText, After:=ActiveCell, LookIn:= _
        xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
        xlNext, MatchCase:=False, SearchFormat:=False).Activate
    ActiveCell.EntireRow.Select
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Try qualifying Cells with sheet
Code:
    [COLOR=#ff0000]ActiveSheet[/COLOR].Cells.Find("X").Activate
 
Upvote 0
Whatever you are looking for probably isn't being found.

As well as specifying the correct sheet to search on you could use something like this to avoid errors.
Code:
Dim DataObj As MSForms.DataObject
Dim rngFnd As Range
 
    Set DataObj = New MSForms.DataObject
    DataObj.GetFromClipboard
    
    
    Sheets("YTD").Select
    Range("A1").Select
    Selection.End(xlDown).Select
    Selection.End(xlToRight).Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1.Copy
    
    With Sheets("Instructions For Use (2)")
        Set rngFnd = Cells.Find(What:=objData.GetText, After:=.Range("A1"), LookIn:= _
        xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
        xlNext, MatchCase:=False, SearchFormat:=False)
    End With
    
    If Not rngFnd Is Nothing Then
        Application.Goto rngFnd.EntireRow, True
    End If

By the way, why are you using the clipboard? Couldn't you put the value from the 'YTD' sheet into a variable and search for that?
 
Upvote 0
By the way, why are you using the clipboard? Couldn't you put the value from the 'YTD' sheet into a variable and search for that?


i ended up going this route and my new code works fantastically. thanks for the idea.
 
Upvote 0

Forum statistics

Threads
1,214,968
Messages
6,122,506
Members
449,089
Latest member
RandomExceller01

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