Conditional Formating count issue

oddworld

Active Member
Joined
May 31, 2005
Messages
250
hi all, i am using the below code to select sheet 2 column "o" and apply conditional formatting to values in column "o" . The issue I have is that for some reason the conditional formatting is being applied to 4993 rows. There are only 49 rows of data, looking at the CF formula it reads =$O$2:$O$4993. The odd thing is that in column a I have employee ID numbers and when summed they = 4993. is there a way to alter the code so that it doesn't count the values in column a and just apply it to values in column o?
Any assistance would be much appreciated.


Code:
Sub CellCCondFormatting()
' This procdure will colour column O values greater and less than 30 credits
Sheets("sheet2").Select
    Dim j As Long
    Range("o2").Select
    j = Range("o2").CurrentRegion.Rows.Count
   
     With Range("o2:o" & j)
        .FormatConditions.Delete
        .FormatConditions.Add Type:=xlCellValue, _
                              Operator:=xlGreater, _
                              Formula1:="=30"
        .FormatConditions(1).Interior.ColorIndex = 3
        .FormatConditions.Add Type:=xlCellValue, _
                               Operator:=xlLess, _
                               Formula1:="=30"
        .FormatConditions(2).Interior.ColorIndex = 4
    End With
   
End Sub
 
Last edited by a moderator:

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
When you say there are only 49 rows of data is that in column O or all columns? When you use current region you are looking at the data around O2 not just column O If you have more rows in other columns this may cause j to be calculated on that higher row count.

Maybe this will work
Code:
j = Cells(Rows.Count, "O").End(xlUp).Row
 
Upvote 0

Forum statistics

Threads
1,216,085
Messages
6,128,733
Members
449,465
Latest member
TAKLAM

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