Match Cells Value On Excel Vba Macro

How do I match cells value from another sheet? And if there is a match can I export value on specific cells?


Here is a generic simple example Say we want to search a worksheet called "pirate island" for a cell containing the text "hidden treasure", If we find a match, we want the contents of the cell to the right of the cell we found.

Here is some code:

Sub MatchGame()
    Dim v As Variant, r As Range, rp As Range
    v = Range("A1").Value
    Set rp = Sheets("pirate island").Cells
    Set r = rp.Find(what:=v, After:=rp(1))
    
    If r Is Nothing Then
        MsgBox "no treasure"
    Else
        MsgBox r.Offset(0, 1).Value
    End If
End Sub

We just put "hidden treasure" in cell A1 of our main sheet and run the macro.