我有一张包含所有商店位置和电子邮件模板的工作表。在电子邮件模板表中,vlookup结果将显示在G25中。我需要G25中的值(例如New Barrie)在另一个表(All Locations)中找到相同的值" New Barrie"。
我不知道如何在G25中寻找价值,而不是硬编码的新巴里。
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
答案 0 :(得分:0)
我相信你会追随以下事情:
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
只需审核LookIn
方法的LookAt
,MatchCase
和Find()
参数,以确保它们确实符合您的需求