Filter results of separate sheet based on another cell text

zefrogi

New Member
Joined
Feb 25, 2022
Messages
15
Office Version
  1. 365
Platform
  1. Windows
I have two sheets setup: One with records, and one with links. I've got the point with the code below where if I double click on the heading "Link" within the Records sheet then it directs to the Links sheet and filters them based upon the reference in the original "Link" heading.

I was wondering, would I be able to still have the "Link" column but have the VBA code take the reference from the Reference column so I can add a formula to count the amount of links within the Links sheet for that reference... Hope this makes sense. So I could double click on the on the formula link in the "Aim" column and have it return the links of that records reference I've clicked on.

My VBA knowledge is much of copy and pasting from this website!

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
   If Target.Column = 3 Then
      Cancel = True
      With Sheets("Links")
         .Range("A1").AutoFilter 1, Target.Value
         Application.Goto .Range("A1"), True
      End With
   End If
End Sub
 

Attachments

  • Screen1.png
    Screen1.png
    11.4 KB · Views: 8
  • Screen2.png
    Screen2.png
    7.8 KB · Views: 7

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Managed to solve this with the code from this link: Excel - How to double click a cell and reference another sheet?

VBA Code:
Option Explicit

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    ' Define constants.
    Const wsName As String = "Links"   ' Destination Worksheet Name
    Const SourceColumn As String = "C"  ' Source Column String
    Const CriteriaColumn As String = "A"
    
    ' Not sure if this is even possible.
    If Target.Rows.Count > 1 Then Exit Sub
    
    If Not Intersect(Target, Columns(SourceColumn)) Is Nothing Then
        Dim Criteria As Variant
        Criteria = Cells(Target.Row, CriteriaColumn)
        If Not IsError(Criteria) And Not IsEmpty(Criteria) Then
            Dim cel As Range
            With ThisWorkbook.Worksheets(wsName)
                .Range("A1").AutoFilter 1, Criteria
                 Application.Goto .Range("A1"), True
            End With
        End If
    End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,926
Messages
6,181,792
Members
453,066
Latest member
Firemonte

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top