Coniditional Formatting Applying Randomly or to Whole Sheet

AlexB123

Board Regular
Joined
Dec 19, 2014
Messages
207
Hi everyone,

I need a macro to change the font of entire rows of data for two conditions.

(1) If column C (age of column B) is greater than 30 days, but less than 61 days, the font should be BOLD and BLACK.
(2) If Column C is greater than 60 days, the font should be BOLD AND RED.

I'm definitely getting frustrated ... this should be so simple.

Code:
   Dim wrkRng As Range
 
  With ActiveWorkbook.Worksheets("Sheet1").Range("A1:M1071")
            .FormatConditions.Delete
            Set wrkRng = ActiveWorkbook.Worksheets("Sheet1").Range("A1:K1071")
        End With
       
   With wrkRng
            .FormatConditions.Add Type:=xlExpression, Formula1:="=AND($C2>30,$C2<=60)"
    With .FormatConditions(1).Font
     .Bold = True
     .Color = RGB(0, 0, 0)
    End With
        End With
    
        With wrkRng
            
            .FormatConditions.Add Type:=xlExpression, Formula1:="=$C2>=61"
            With .FormatConditions(2).Font
                .Bold = True
                .Color = RGB(255, 0, 0)
            End With
        End With
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try
Code:
   Dim wrkRng As Range
   
   With ActiveWorkbook.Worksheets("Sheet1").Range("A1:M1071")
      .FormatConditions.Delete
   End With
   Set wrkRng = ActiveWorkbook.Worksheets("Sheet1").Range("A2:K1071")

   With wrkRng
      .FormatConditions.Add Type:=xlExpression, Formula1:="=AND($C2>30,$C2<=60)"
      With .FormatConditions(1).Font
         .Bold = True
         .Color = RGB(0, 0, 0)
      End With
   End With
   
   With wrkRng
      .FormatConditions.Add Type:=xlExpression, Formula1:="=$C2>=61"
      With .FormatConditions(2).Font
         .Bold = True
         .Color = RGB(255, 0, 0)
      End With
   End With
 
Upvote 0
Still not working ... It's like the program doesn't even recognize the parameters??? But when I check the conditional formatting rules, after the program runs, they exist and are as required. The spreadsheet just isn't implementing it ... or at least it implements it incorrectly. For instance, I have one row that the format turned to red, but the value in the Age column is 7?
 
Upvote 0
Are the values in col C hard values, or the result of formulae?
Also check if there is any cell formatting on that column.
 
Upvote 0
Are the values in col C hard values, or the result of formulae?
Also check if there is any cell formatting on that column.
@Fluff, the cells are hard coded, and there is no formatting.

After I run my code, there are rules created under conditional formatting. They just seem to be rather confused.

Sorry for the delay, we had a holiday and then I was slammed with other requirements. Thanks!
 
Upvote 0
Would you be able to share your workbook?
With the code in post#2 I get


Excel 2013/2016
C
1Age
254
358
429
531
678
72
877
982
1071
115
1242
1340
1422
1560
Sheet1


The blue cells are for bold black text, & the Red cells are for bold red text
 
Upvote 0
You can upload a file to a share site, such as OneDrive, DropBox, GoogleDrive. Mark for sharing & post the link to the thread.
 
Upvote 0
I don't believe I'll be able to share any workbooks :(

Any ideas as to what could cause an error? I ran just the top code on a different sheet, with simplified data, and am still getting odd results.

For this test ... columns were
A B C D
StringNumber ClientName Age Date

003 ABC 17 10/28/18 (this was bold, which should not fall within parameters)

023 XYZ 34 10/12/18 (this one was not bold, but did fall within parameters).


Any suggestions as to troubleshooting?
 
Upvote 0
If you look at the CF rules & applies to range, are they correct?
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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