Find a copied cell value

Excel Newbie7

New Member
Joined
Nov 18, 2013
Messages
9
Hello All,

I have a problem that I just can't seem to figure out. :confused:

After using a vlookup formula, and a if then statment I found out that there are duplicates on my other sheets. I want to use a Macro to use the duplicate value in search and find to locate the item and highlight it on my other sheet. I have searched the web but can't find anything on this.

I can't seem to paste my coppied cell into the what in the find.


Sub Macro15()
'
' Macro15 Macro
'
'
Selection.Copy
Sheets("BAC Box").Select
Cells.Find(What:="Selection.paste", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Application.CutCopyMode = False
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End Sub



Thanks you,
 

jsotola

Well-known Member
Joined
Nov 15, 2013
Messages
524
Selection.paste is a command to paste the contents of the clipboard into the selected worksheet cell

it does not provide a value to the vba macro

you need to retrieve the value of the selected cell

Code:
Sub Macro15()
    
[COLOR=#ff0000]    Dim tmp As Variant[/COLOR]
    
    [COLOR=#ff0000]tmp = [/COLOR]Selection[COLOR=#ff0000].Value[/COLOR]
    
    Sheets("BAC Box").Select
    
    Cells.Find(What:=[COLOR=#ff0000]tmp[/COLOR], After:=ActiveCell, LookIn:=xlFormulas, _
               LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
               MatchCase:=False, SearchFormat:=False).Activate
    
    Application.CutCopyMode = False
    
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With


End Sub
 
Last edited:

Forum statistics

Threads
1,081,556
Messages
5,359,555
Members
400,533
Latest member
fpenning

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top