点击search,然后转到工作簿中的单元格

我想知道有没有人可以帮助我。

我有一个工作簿,有几个选项卡和一个主页面。

在主页上我有一个自动填充问题的前20名。 我想要做的是自动创build“数字”行上的超链接,当我点击它们来search工作簿中的数字,并去。 类似于CTRL + F。

 数量 - 问题 - 状态   
 IM123
 IM124
 IM145
等等.. 

有人能帮我吗?

谢谢

Worksheet_SelectionChange事件中,您可以使用类似这样的方式来search数据

 If Not Intersect(Target, Range("A1:A4")) Is Nothing Then If Target.Count = 1 Then Cells.Find(What:=Target.Value, LookIn:=xlFormulas, LookAt:= _ xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ After:=ActiveCell, SearchFormat:=False).Activate End If End If 

只要您在指定的范围(A1:A4)中,并且您只select了一个单元格(Target.Count = 1),则会移至包含与您单击的单元格相同的数据的下一个单元格。

以下将search您select的单元格中的任何数字。 除了find第一个结果之外,它会询问您是否要继续search下一个结果。 这样,如果您有多个问题的实例,您可以“循环”通过工作表中find的所有结果。 它也会忽略包含前20个问题的MainWorksheet中的search结果。 Cells.Find本身只会返回find的第一个结果,即使它在同一个工作表中。

它还会告诉你是否在每张表格中find问题编号,以及何时检查了所有的工作表(如果没有find更多的结果)。 如果您回应您不想继续search,则会转到在最近检查的工作表中find的问题编号的第一个实例。

为了模拟一个超链接,你需要使用一个工作表事件,比如Intersect(在Sean的答案中描述)或者FollowHyperlink。 就个人而言,我更喜欢在可能的情况下使用工作表事件的替代scheme,因为即使在意外情况下,它们也会始终触发。 例如,您可以创build一个形状或macrosbutton并将其分配给它。 这样,代码将只在用户点击button时运行。

另外,请在发现问题后告诉我们您是否确实想要做更多的事情。 例如,您可以自动对相关单元格进行更改,或者创build所发现问题(或所有问题)的所有实例的列表。

祝你好运!

 'Create a string variable to store the problem status Dim StringProblemStatus As String 'Create a string variable to store the worksheet name of the main page containing the problem status Dim StringMainWorksheet 'Create a range variable to store the results of the Find method Dim RangeFindResults As Range 'Create an integer variable to store the current worksheet number Dim IntegerSheetCount As Integer 'Set the variable to the problem status stored in the current cell StringProblemStatus = Selection.Value 'Set the variable to the worksheet name containing the problem status StringMainWorksheet = ActiveSheet.Name 'Create a For/Next loop so that the following code will evaluate all worksheets in the workbook For IntegerSheetCount = 1 To ActiveWorkbook.Sheets.Count Sheets(IntegerSheetCount).Activate 'Search for the problem number within the worksheet 'Check that the sheet being searched is not the MainWorksheet If ActiveSheet.Name <> StringMainWorksheet Then 'Searches for exact matches Set RangeFindResults = _ Cells.Find( _ What:=StringProblemStatus, _ After:=ActiveCell, _ LookIn:=xlFormulas, _ LookAt:=xlWhole, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False, _ SearchFormat:=False _ ) 'Returns a message to the user if the status is not found If RangeFindResults Is Nothing Then MsgBox "Problem Status " & StringProblemStatus & " was not found in worksheet " & Sheets(IntegerSheetCount).Name Else 'Returns a message to the user if the status is found If MsgBox("Problem Status " & RangeFindResults & " found in worksheet " & _ Sheets(IntegerSheetCount).Name & " in cell " & " " & RangeFindResults.Address & _ ". Continue searching?", vbYesNo) = vbNo Then RangeFindResults.Activate Exit Sub End If End If End If 'Move to the next worksheet Next IntegerSheetCount 'Notify the user that all worksheets have been searched MsgBox "All worksheets searched" End Sub