单击Excel中的超链接可以在其他工作表上设置自动filter

我有两张工作表的Excel工作簿,基本上是两张纸之间的一对多的设置。 第一张表列出了几百家公司,第二张表列出了公司的董事会。 第二张纸具有自动filter,用户可以看到从filter中select的特定公司的董事会成员。

我试图做的是让用户在第一张纸上点击公司的单元格,这样用户就会被带到下一张纸上,自动filter已经被公司选中。 这样,用户只能直接访问董事会成员选定的公司。

我想这将需要VBA,并希望有人能指出我正确的方向来创build此代码来解决这个问题。 非常感谢。

您可以通过在工作表模块中执行以下操作来完成此操作:

 Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) 'Update Table14 to your table name 'Update Field to column number of the field you are filtering 'Update Sheet7 to reference the sheet containing your table 'Change on to the column number where your click should cause this action If ActiveCell.Column = 1 Then Sheet7.ListObjects("Table14").Range.AutoFilter Field:=1, Criteria1:=ActiveCell.Value 'Update Sheet7 to reference the sheet containing your table Sheet7.Activate End If End Sub 

您需要打开Visual Basic编辑器,右键单击公司工作表,查看代码,将其粘贴到:

 Option Explicit Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim CompanyName As String If Selection.Count = 1 Then If Not Intersect(Target, Range("C1").EntireColumn) Is Nothing Then 'This code is triggered when any 'ONE cell in column C is selected 'Simply change "C1" to "B1" etc etc 'This MsgBox returns the selected cell MsgBox Target.Address 'You'll probably need to collect some information 'in this section. You can then use this to affect 'the filters on sheet 2. 'Perhaps like this CompanyName = Cells(Target.Row, 1).Value MsgBox CompanyName 'This changes to "Sheet2" Sheets("Sheet2").Activate End If End If End Sub 

希望有所帮助,你可以做些什么