skip if nothing found ? autofilter

RompStar

Well-known Member
Joined
Mar 25, 2005
Messages
1,200
I have this code that unhides a column and then select using autofilter a value

The thing is that when there are no entries for RRP (as I don't know which sheets will have it as I loop sheet), it highlights the rows red, even if there is nothing there ? it highlights it RED, and I only need that to highlight for rows with value of RRP.

What is the best way to edit this so that if there is no rows with values of RRP, it just skips to end of this code ?


With Range("A6:AH" & lr) ' SORT #4 When GTP is blank and Done.value=X, then SORT and highlight light purple
On Error Resume Next

Columns("R:T").Select
Range("T1").Activate
Selection.EntireColumn.Hidden = False
Range("S6").Select
Selection.AutoFilter
Selection.AutoFilter Field:=19, Criteria1:="RRP"

.Sort Key1:=Range("C7"), Order1:=xlAscending, Key2:=Range( _
"D7"), Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase _
:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal

Range("A7:AH" & lr).Select
With Selection.Interior
.ColorIndex = 3 ' RED
.Pattern = xlSolid
Range("AI7:AI" & lr).Value = 4
End With

.AutoFilter ' turn the autofilter off on the last sort ( next month we have to add a 4th sort (RED-for RR that make it into the sheet)

End With
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
You can test for the existence like this:

If WorksheetFunction.CountIf(Range("S7:S" & lr, "RRP") > 0 Then
 
Upvote 0
that whole line is highlighted red, what could be the problem ?

Ohhh, I think the right bracket was missing

If WorksheetFunction.CountIf(Range("S7:S" & lr, "RRP") > 0) Then
 
Last edited:
Upvote 0
still problem

If WorksheetFunction.CountIf(Range("S7:S" & lr, "RRP") > 0) Then

it highlight .Countif and error: compile error, argument not optional, any idea ?
 
Upvote 0
Try this.

Code:
If WorksheetFunction.CountIf(Range("S7:S" & lr), "RRP") > 0 Then
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,434
Members
448,961
Latest member
nzskater

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