Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

vba - Clicking a hyperlink in Excel to set autofilter on a different sheet

I have an Excel workbook with two sheets, basically a one-to-many setup between the two sheets. The first sheet lists several hundred companies and the second sheet lists the board of directors of the companies. The second sheet has an auto filter so users can see board members for a specific company selected from the filter.

What I am attempting to do is have a user click the cell of the company on the first sheet so the user is then taken to the next sheet with the auto filter already populated with the company selected. That way the user has direct access to the Board Members only for the company selected.

I imagine this would require VBA and was hoping someone could point me in the right direction for creating this code to solve this. Many thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can accomplish this by doing something this in the worksheet module:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...