How to filter data in one sheet just by clicking cell content in a different sheet in Excel?

isabelarodriigs

New Member
Joined
Jan 14, 2025
Messages
7
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. Web
I would like to to click on on my sheet 1 in excel and automatically filter on my third sheet. I using this code:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("A:C")) Is Nothing Then Exit Sub
With Sheets("mydata").Cells(7, 1).CurrentRegion
.AutoFilter 1, Target.Offset(, -1)
.AutoFilter 2, "Completed"
End With
End Sub

but when i double click, i get to run-time error '9'. Subscript out of range. Then it highlights this part With Sheets("mydata").Cells(7, 1).CurrentRegion
saying that table does not exist, but it does.

this is my sheet 1:

DIVISION ID
DIVISION NAME
DEPARTMENT ID
Updated to Loma Linda Department ID/GL
CURRENT IM DEPARTMENT NAME
9423
RECORDS MANAGEMENT
20004
20004

my second sheet:


CUSTOMER IDCUSTOMER NAMEDISTRICT IDDISTRICT NAMEDIVISION IDDIVISION NAMEDEPARTMENT ID
LLUHSLOMA LINDA UNIVERSITY HEALTH SYSTEMLALOS ANGELES, CALLUMCLOMA LINDA UNIVERSITY MEDICAL CTR 8154


I want to click on sheet 1, column C, and filter automatically sheet2, column G.
 
File/Save As/ and scroll to select either of those formats. I assume you tried to run it merely by double clicking on a cell on the DivandDep sheet? What line of code did the error occur on?
It does not show which line the error is coming from. I saved the document in the format you said it
 

Attachments

  • Screenshot (5).png
    Screenshot (5).png
    17.5 KB · Views: 4
  • Screenshot (6).png
    Screenshot (6).png
    184.4 KB · Views: 4
Upvote 0

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
The problem is you don't have a sheet called "mydata". Is it the sheet you've called "L1897128" that you want to filter? If so, change the following line of code to be:

Rich (BB code):
With Sheets("L1897128")
 
Upvote 0
Looking at your images, you don't have a sheet called "mydata"? :unsure:
I renamed the sheet in the third tab "mydata", so when you press CTRL A, thats what pop up. but the bottom of my third tab, the name is L1897128
 

Attachments

  • Screenshot (7).png
    Screenshot (7).png
    207.3 KB · Views: 2
Upvote 0
The problem is you don't have a sheet called "mydata". Is it the sheet you've called "L1897128" that you want to filter? If so, change the following line of code to be:

Rich (BB code):
With Sheets("L1897128")
YOU ARE AWESOME!!!! THANK YOU!!!!! ❤️❤️❤️❤️❤️❤️❤️
 
Upvote 0

Forum statistics

Threads
1,225,627
Messages
6,186,100
Members
453,337
Latest member
fiaz ahmad

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