Apply worksheet function in module

Vincent88

Active Member
Joined
Mar 5, 2021
Messages
382
Office Version
  1. 2019
Platform
  1. Windows
  2. Mobile
Hi Guys,
I want to apply the below function in a vba module. Please help how it should be. Thanks

Count the total number of blank cells, "AL" and "VL" from cells 3 to end of last row in a column
Application.WorksheetFunction.If(Sum(CountIfs(Range(vRngCol.Cells(3), vRngCol.Cells(vLastRow)), "", "AL", "VL")) > 2, "True", "False") = True

Debug finds error in IF(SUM(COUNTIFS .


VBA Code:
Sub GetAbsence15()

    Dim vRng As Range
    Dim vLastRow As Long
    Dim vRngCol As Range
    
    With ThisWorkbook.ActiveSheet
        vLastRow = .Cells(Rows.Count, "A").End(xlUp).Row
        Set vRng = Range("C1", Range("AL" & vLastRow))
        For Each vRngCol In vRng.Columns
            If IsWeekend(vRngCol.Cells(1)) = False Then
            
                With Columns(vRngCol.Column)
                'Count total number of blank cells, "AL" and "VL" from the 3rd row till lastrow in a column
                Dim LvTtl As Boolean
                LvTtl = Application.WorksheetFunction.If(Sum(CountIfs(Range(vRngCol.Cells(3), vRngCol.Cells(vLastRow)), "", "AL", "VL")) > 2, "True", "False") = True
                   If LvTtl = True Then
                      vRngCol.Cells(2).Font.Size = 18
                End With
                
             Else
                      vRngCol.Cells(2).Font.Size = 12
                              
            End If
  
        Next vRngCol
    End With
    
 End Sub
 
You can try to replace a code with this...
VBA Code:
Sub GetAbsence15()

    Dim vRng
    Dim vLastRow As Long, vN As Long, vC As Long
    Dim vRngCol As Integer
    
    With ThisWorkbook.ActiveSheet
        vLastRow = .Cells(Rows.Count, "A").End(xlUp).Row
        vRng = .Range("C1", .Range("AL" & vLastRow))
        vC = UBound(Application.Transpose(vRng))
        For vRngCol = 1 To vC
            For vN = 3 To UBound(vRng)
               If vRng(vN, vRngCol) = "" Or _
                  vRng(vN, vRngCol) = "AL" Or _
                  vRng(vN, vRngCol) = "VL" Then _
                  LvTtl = LvTtl + 1
            Next vN
            If IsWeekend(.Columns(vRngCol + 2).Cells(1)) = False Then
                If LvTtl > 2 Then
                    .Range(Cells(1, vRngCol + 2), _
                           Cells(vLastRow, vRngCol + 2)) _
                    .Font.Size = 18
                Else
                    .Range(Cells(1, vRngCol + 2), _
                          Cells(vLastRow, vRngCol + 2)) _
                    .Font.Size = 12
                End If
            End If
            LvTtl = 0
        Next vRngCol
    End With

End Sub
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,215,094
Messages
6,123,071
Members
449,092
Latest member
ipruravindra

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