2016-11-12 1 views
0

Ich habe ein Blatt mit allen Speicherorten und einer E-Mail-Vorlage. In der E-Mail-Vorlage wird ein vlookup-Ergebnis in G25 angezeigt. Ich benötige den Wert in G25 (z. B. New Barrie), um in einem anderen Blatt (All Locations) den gleichen Wert "New Barrie" zu finden.Ermitteln Sie den Zellenwert, um in einem anderen Blatt den gleichen Wert zu finden

Ich weiß nicht, wie man den Wert in G25 anstelle des hardcoded New Barrie sucht.

Sub Email() 

' Email Macro 

Range("G25").Select 

Selection.Copy 

Sheets("All Locations").Select 

Cells.Find(What:="New Barrie", After:=ActiveCell, LookIn:= _ 

    xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _ 

    xlNext, MatchCase:=False, SearchFormat:=False).Activate 

Range("A37").Select 

Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True 

Sheets("Email Template").Select 

End Sub 

Antwort

0

Ich glaube, du bist nach etwas wie folgt:

Option Explicit 

Sub Email() 
    Dim val As String 
    Dim myCell As Range 

    val = Worksheets("template").Range("G25").Value '<--| store worksheet "template" cell "G25" value into a string variable 
    Set myCell = Worksheets("All Locations").Cells.Find(What:=val, LookIn:=xlFormulas, _ 
       LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ 
       MatchCase:=False, SearchFormat:=False) '<--| set myCell to the one in "All Locations" worksheet whose content matches the stored value 

    If Not myCell Is Nothing Then myCell.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True 
End Sub 

nur LookIn, LookAt und MatchCase Argumente von Find() Methode überprüfen um sicher zu sein sie Ihren Bedarf tatsächlich passt

+0

@Jira, tat kommst du durch? – user3598756

+0

Vielen Dank für Ihre Hilfe, es hat funktioniert :) – Jira

+0

Gern geschehen. Vielleicht möchten Sie die Antwort als akzeptiert markieren. Vielen Dank! – user3598756

Verwandte Themen