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
 

Some videos you may like

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

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
75,764
Office Version
365
Platform
Windows
Try this.

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

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,513
Messages
5,511,731
Members
408,864
Latest member
cmajewsk

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top