Countif Failing Due To Different Comparison Types (Dates)

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,218
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am having difficulty with this code

VBA Code:
Set wb_rmrsrc = Workbooks.Open(anpath & "rmr1.xlsx", True, True)
Set ws_rmrsource = wb_rmrsrc.Worksheets("Sheet1")
cnt_idate = Application.WorksheetFunction.CountIf(ws_rmrsource.Columns(1), inq_date)

inq_date = 44023 (serial of July 12, 2020)
wb_rmsrc is accessed in the background but not opened
column 1 of ws_rmrsource contains dates, but I think they may be text. When I try to change their cell format to number, nothing happens so I assume that they aren;t true dates.

I am getting a value of 0 for cnt_date when the datavase should find 8 equal date values.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,218
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Code:
cnt_idate = Application.WorksheetFunction.CountIf(ws_rmrsource.Columns(1), CDate(inq_date))

Thank you!
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,063
Messages
5,835,184
Members
430,344
Latest member
ralstad2

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
Top