If Condition Before Filtering

Flani

New Member
Joined
Jul 11, 2012
Messages
17
So I am stuck with this code. What I want to happen is when rg is non blank, the macro will filter sheet imagine column b starting in row 12. down (number of rows varies everyday) and saves a screenshot (i have a macro code for this already). code below needs adjustments.


Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = False
ActiveSheet.AutoFilterMode = False


Set rg = Sheets("MACRO").Range("F14")
Range("a12").AutoFilter
If rg.Value <> "" Then Range("A12").AutoFilter Field:=2, Criteria1:=rg.Value
End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
your code is failing because the range "A12" doesn't have a second column... you could try (although untested)

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = False
ActiveSheet.AutoFilterMode = False




Set rg = Sheets("MACRO").Range("F14")
Range("a12").AutoFilter
If rg.Value <> "" Then Range("A12:B12").AutoFilter Field:=2, Criteria1:=rg.Value
'or If rg.Value <> "" Then Range("A12").AutoFilter Field:=1, Criteria1:=rg.Value
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,452
Messages
6,124,915
Members
449,195
Latest member
Stevenciu

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