filter row on value from another sheet in the same workbook

VbaHell

Well-known Member
Joined
Jan 30, 2011
Messages
1,220
Hello all

I hope you can help on this one

Is it possible to filter your data based on a value from another worksheet in the same workbook.
I want to filter on any rows not equal to "<> INST", This is the code I have am playing with but it's not working, I can get it to work if I hard code it to "<>INST" but I wanted the flexibility of change the value in sheet5 cell "C2"

Code:
With Sheets("Data")
      If .AutoFilterMode Then .AutoFilterMode = False
      .Range("N:N").AutoFilter 1, "<>" & Sheet5.Range("C2")
      .AutoFilter.Range.Offset(1).EntireRow.Delete
      .AutoFilterMode = False
   End With
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
As long as C2 contains INST then that code should work.
Check C2 for any leading/trailing spaces, also check that you are looking at the correct sheet, ie sheet codename "Sheet5" rather than sheet name
 
Upvote 0
Hi Fluff

I can see that the filter is working now but I get this error message on the next line highlited in bold- application defined or object defined error

Code:
[LEFT][COLOR=#333333][FONT=monospace]With Sheets("Data")
      If .AutoFilterMode Then .AutoFilterMode = False
      .Range("N:N").AutoFilter 1, "<>" & Sheet5.Range("C2")
      [B].AutoFilter.Range.Offset(1).EntireRow.Delete[/B]
      .AutoFilterMode = False
   End With[/FONT][/COLOR][/LEFT]
 
Upvote 0
You cannot use offset(1) when working on the entire column. try
Code:
      Intersect(.UsedRange, .Range("N:N")).AutoFilter 1, "<>" & Sheet2.Range("C2")
 
Upvote 0
Hi Fluff

I am still battling with this and I have searched the net trying to find a solution

I have columns "A:AC" and want to filter on column "N" and then delete any rows NOT equal to Sheet5.Range("C2")

Code:
With Sheets("Data")
      If .AutoFilterMode Then .AutoFilterMode = False
         .[COLOR=#333333][FONT=monospace]Intersect(.UsedRange, .Range("N:N")).AutoFilter 1, "<>" & Sheet2.Range("C2")[/FONT][/COLOR]      
         .AutoFilter.Range.Offset(1).EntireRow.Delete
         .AutoFilterMode = False
   End With
 
Last edited:
Upvote 0
You need to change the sheet reference in the autofilter
 
Upvote 0
Do you mean like this

Code:
With Sheets("Data")
      If .AutoFilterMode Then .AutoFilterMode = False
         Intersect(.UsedRange, .Range("N:N")).AutoFilter 1, "<>" & Sheet2.Range("C2")
         .AutoFilter.Range("N:N").EntireRow.Delete
         .AutoFilterMode = False
   End With
 
Upvote 0
The criteria is currently looking at Sheet2, not sheet5
 
Upvote 0
I have changed the criteria from Sheet2 to Sheet5


Code:
With Sheets("Data")
      If .AutoFilterMode Then .AutoFilterMode = False
         Intersect(.UsedRange, .Range("N:N")).AutoFilter 1, "<>" & Sheet5.Range("C2")
         .AutoFilter.Range("N:N").EntireRow.Delete
         .AutoFilterMode = False
     End With
 
Upvote 0
Why have you changed this line?
Code:
.AutoFilter.Range("N:N").EntireRow.Delete
 
Upvote 0

Forum statistics

Threads
1,216,098
Messages
6,128,812
Members
449,468
Latest member
AGreen17

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