VBA formatting cell based on conditions in a column

Vincent88

Active Member
Joined
Mar 5, 2021
Messages
382
Office Version
  1. 2019
Platform
  1. Windows
  2. Mobile
Hi Everybody,
How to make the code works - I want to check if totol amount of cells contain blank cell, "AL" and/or "VL" in a column more than 2 but this is applicable in workdays only.

VBA Code:
Option Explicit

Sub CheckLvCol()

    Dim rng As Range
    Dim lastrow As Long
    Dim rngCol As Range
    Dim sVal As Boolean
    
    lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    lastrowd = Sheets("Data").Cells(Rows.Count, "A").End(xlUp).Row
    
    Set rng = Range("C1", Range("AL" & lastrow))
    
                 rngCol.Cells(2).Font.Color = vbBlack
    
    For Each rngCol In rng.Columns
       'Restrict conditions to WORKDAYS ONLY
       '=IF(WORKDAY((C1-1),1,TableNew[Holidays (A2:End)])=C1,IF(SUM(COUNTIFS(Table22[(5)],{"","AL","VL"}))>2,3,0),0)=3
        'sVal=application.WorksheetFunction.IF(WORKDAY((rngcol.Cells(1)-1),1,sheets("Data").range("A2:A"&lastrow1)=rngCol.Cells(1),IF(SUM(COUNTIFS(rngCol,{"","AL","VL"}))>2,3,0),0)=3
        sVal=evaluate("IF(WORKDAY((rngcol.Cells(1)-1),1, Sheets("Data").Range("A2:A" & lastrowd)=rngCol.Cells(1), IF(SUM(COUNTIFS(rngCol,{"","AL","VL"}))>2,3,0),0)=3")
        If sVal = True Then
                 rngCol.Cells(2).Font.Color = vbRed
                
        Else
                 rngCol.Cells(2).Font.Color = vbBlack
              
    Next rngCol
    
 End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

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