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

前端 未结 2 1230

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

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-18 14:00

    You'll need to open the visual basic editor, right click the company worksheet, view code, paste this in:

    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
    

    Hope that helps and you can make something of it

提交回复
热议问题