Trouble with COUNTIFS function on cell values obtained through VBA

masud8956

Board Regular
Joined
Oct 22, 2016
Messages
163
Office Version
  1. 2016
  2. 2011
  3. 2007
Platform
  1. Windows
Hi,

I am trying to use the following formula to count no of 'date' entries within a specific range between two dates at E7 and E8.

=COUNTIFS($F$8:$F$107,">="&$E$7,$F$8:$F$107,"<="&$E$8)

The values within the range F8:F107 are dates (stamped through a VBA).

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim Chng As Range, Cl As Range
   
   Set Chng = Intersect(Target, Range("F8:F107,K8:K107,O8:O107,S8:S107,W8:W107"))
   If Not Chng Is Nothing Then
      Me.Unprotect "password"
      For Each Cl In Chng
         If Cl.Value = "" Then
            Cl.Offset(, -1).Value = ""
         Else
            Cl.Offset(, -1).Value = Format(Date, "dd mmm yy (ddd)")
         End If
      Next Cl
      Me.Protect "password"
   End If
End Sub

The COUNIFS formula returns zero value. But it works fine on a range which is not populated through VBA code.

How can I get the formula work using data from F, K, O, S and W columns?

Thanks
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
You are putting text into the cells, not a true date. You should format the cells, not the text:

Code:
       Private Sub Worksheet_Change(ByVal Target As Range)
Dim Chng As Range, Cl As Range

Set Chng = Intersect(Target, Range("F8:F107,K8:K107,O8:O107,S8:S107,W8:W107"))
If Not Chng Is Nothing Then
Me.Unprotect "password"
For Each Cl In Chng
If Cl.Value = "" Then
Cl.Offset(, -1).Value = ""
Else
with Cl.Offset(, -1)
    .Value = Date
    .Numberformat = "dd mmm yy (ddd)"
end with
End If
Next Cl
Me.Protect "password"
End If
End Sub
 
Upvote 0
Solution
Works fine with the modified code. Thanks a lot!
 
Upvote 0
Glad to help. :)
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,607
Members
449,090
Latest member
vivek chauhan

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