Conditional Formatting not applying correctly to last row added from ListRows.Add loop

WhitAP

New Member
Joined
Feb 6, 2022
Messages
1
Office Version
  1. 2021
Platform
  1. Windows
I maintain a time log of my activity throughout the day.

I have a short little bit of code (below) that adds five new rows to the bottom of my table with today's date in the first column. It does that, but for the last row, the existing Conditional Formatting rules don't apply correctly.
  • If I manually type the date over, the Conditional Formatting does not apply itself.
  • If I delete the date, then type the date, the Conditional Formatting does not apply itself.
  • If I open Conditional Formatting > Manage Rules and hit OK, the Conditional Formatting does not apply itself. The Applies to range is listed correctly.
  • If I open Conditional Formatting > Manage Rules and select the Applies to range for either of my rules -- and do nothing else -- and hit OK, the Conditional Formatting applies correctly.
  • If I run the code twice, when it runs the second time, the Conditional Formatting applies correctly to the previous "last line" but does not apply correctly to what is now the last line. No matter how many times the code runs, only the last line's Conditional Formatting is incorrect.
The Conditional Formatting rules (B is the column containing dates, 5 is the first row of the table):

=ISEVEN($B5) (applies to entire table)
=ISODD($B5) (applies to entire table)

So the visual end result is color banding by alternating dates (the values in Column B) rather than alternating rows.

Solutions would be greatly appreciated -- I've found a lot of near misses, but nothing directly on target. Something that just forces the Conditional Formatting rules to run? Something that pastes formatting from the first row to the added row?

VBA Code:
Sub Add_Five_Rows()

Dim count As Integer
Dim daterow As ListRow


    For count = 1 To 5

        Set daterow = wsLog.ListObjects("TblLog").ListRows.Add
        
            With daterow
            
                .Range(1).Value = Date
                
            End With
                       
    Next
   
End Sub
 

Excel Facts

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

Forum statistics

Threads
1,215,577
Messages
6,125,637
Members
449,242
Latest member
Mari_mariou

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