Countif Failing Due To Different Comparison Types (Dates)

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
3,893
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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Ark68

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

Thank you!
 

Watch MrExcel Video

Forum statistics

Threads
1,130,329
Messages
5,641,545
Members
417,219
Latest member
FrancoisT

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