IF statement for fill color?

paquirl

Board Regular
Joined
Oct 12, 2010
Messages
226
Office Version
  1. 2016
Platform
  1. Windows
After filtering a column for a fill color yellow:

Code:
ActiveSheet.Range("$A$1:$AB$1217").AutoFilter Field:=11, Criteria1:=RGB(255 _
        , 255, 0), Operator:=xlFilterCellColor

I want to then do an IF THEN logic command as follows: IF no yellow filled cells exist in Field:=11, THEN skip to another step (4 steps down). Can anyone help me figure out how to do this IF THEN command?
 
This is not working :(

Code:
ActiveSheet.Range("$A$1:$AB$1217").AutoFilter Field:=11, Criteria1:=RGB(255 _        , 255, 0), Operator:=xlFilterCellColor
            
    'IF no yellow exists, THEN END SUB
        If Range("K2:K1217").End(xlUp).Row < 1 Then
               Exit Sub
        End If
        
        If Range("K2:K1217").End(xlUp).Row > 1 Then
    'Populate formula in BEST MATCH column [=Suggested UPC column]
        Range("R2:R1217").SpecialCells(xlVisible).Formula = "=RC[-7]"
        End If
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
THIS SEEMS TO WORK THO!

Code:
If Range("K2:K1217").End(xlUp).Row <> RGB(255, 255, 0) Then            ActiveSheet.Range("$A$1:$AB$1217").AutoFilter Field:=11
            Exit Sub
        End If
 
Upvote 0
Code:
Sub CCT1_BLUE_YELLOW()                        
        Columns("K:K").Select
        Selection.NumberFormat = "00000000000"
        
        Columns("N:N").Select
        Selection.NumberFormat = "00000000000"
                
    'Filter SUGGESTED UPC column for highlighted stock parts (yellow fill)
        ActiveSheet.Range("$A$1:$AB$1217").AutoFilter Field:=11, Criteria1:=RGB(255 _
        , 255, 0), Operator:=xlFilterCellColor
            
    'IF no yellow exists, THEN EXIT SUB
        If Range("K2:K1217").End(xlUp).Row <> RGB(255, 255, 0) Then
        Exit Sub
        End If
        
    'Populate formula in BEST MATCH column corresponding to any yellow cells that got filtered in column K
        If Range("K2:K1217").End(xlUp).Row > 1 Then
           Range("R2:R1217").SpecialCells(xlVisible).Formula = "=RC[-7]"
        End If
        
    'Remove filter from SUGGESTED UPC column
        ActiveSheet.Range("$A$1:$AB$1217").AutoFilter Field:=11
      
End Sub

I want it to get to column K, filter for any yellow-filled cells, and if there are none, exit this sub routine, but then continue on to any subsequent sub routines. If yellow filled cells exist, don't exit the sub, continue on to the formula fill.

What's happening during the debug process is when it gets to the "exit sub" command it is just exiting the sub. It isn't taking into account the logic statement.
 
Upvote 0

Forum statistics

Threads
1,215,731
Messages
6,126,537
Members
449,316
Latest member
sravya

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