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

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
You can test for the existence like this:

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

RompStar

Well-known Member
Joined
Mar 25, 2005
Messages
1,200
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:

RompStar

Well-known Member
Joined
Mar 25, 2005
Messages
1,200
still problem

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

it highlight .Countif and error: compile error, argument not optional, any idea ?
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,343
Office Version
  1. 365
Platform
  1. Windows
Try this.

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

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,726
Messages
5,833,322
Members
430,205
Latest member
chang2807

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
Top