Quantcast
Channel: Excel IT Pro Discussions forum
Viewing all articles
Browse latest Browse all 11829

Excel VBA date bug

$
0
0

This error was found in Excel 2010 32 bit but may be present in other versions. The error happens when writing specific dates to an Excel cell. The VBA code

Dim datDate as Date

datDate = CVDate(41586.9999999995)
ActiveWorkbook.Sheets("Sheet1").Cells(3, 2).Value=datDate

ActiveWorkbook.Sheets("Sheet1").Cells(3, 2).Value=CDbl(41586.9999999995)

Will result in the following output to the Excel sheet

11/8/2013 0:00
11/9/2013 0:00

Both dates should be 11/9/2013. The error happens when writing a date to an Excel cell when the is almost (less than a second) before midnight. The conversion of the variable from date to double precision type fixes the bug.


Viewing all articles
Browse latest Browse all 11829

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>