VBA For Autofilter with IF/THEN Statement

srj1359

New Member
Joined
Mar 5, 2015
Messages
46
Office Version
  1. 2016
Platform
  1. Windows
I'm trying to write VBA so column AG is filtered to just show "Yes" and then I want to highlight those rows, then clear the autofilter. The problem I'm encountering is if there is no "Yes" in that column, I get an error message. Is it possible to write code that would say if the autofilter on AG = "Yes" then highlight those rows and if not (or if the autofilter on AG = "No" then do nothing? Below is what I have at the moment. Any assistance you can provide is grealty appreciated. Thank you!


With Sheets("Title List")
Sheets("Title List").Select
Columns("AG").Select
Selection.EntireColumn.Hidden = False
lr2 = .Range("A" & Rows.count).End(3).Row
.Range("AG2:AG" & lr2).Formula = "=IFERROR(IF(MATCH('Title List'!AF:AF,'Holdings List'!AF:AF,0),""Yes"",),""No"")"
End With

Application.ScreenUpdating = False

'Add yellow highlighting to owned titles
With Sheets("Title List")
Sheets("Title List").Select
Range("AG2:AG").AutoFilter Field:=33, Criteria1:="<>No"
lr2 = .Range("A" & Rows.count).End(3).Row
.Range("A:AG" & lr2).Select
End With

With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With

'Clear yellow highlighting from headers
Range("AG:AG").AutoFilter Field:=33
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Columns("AG").Select
Selection.EntireColumn.Hidden = True
Range("A1").Select
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Maybe something like this...
VBA Code:
    If Application.CountIf(Columns("AG"), "Yes") > 0 Then
    'Add yellow highlighting to owned titles
 
Upvote 0
Solution

Forum statistics

Threads
1,213,561
Messages
6,114,315
Members
448,564
Latest member
ED38

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