Excel: Runtime Error "13" Type Mismatch

What could be the reason why I get a "13" runtime error matching this VBA line of code:

.Cells(1, 1) = CDate(Format(Now, "dd.mm.yy hh:mm")) 

The problem is that a colleague is not getting this error. We also have a "German" office.

+6
source share
1 answer

I'm not sure why the format is needed, as it was simply returned back to the Date before you fill out the cell.

You really must have:

 .Cells(1, 1) = Format(Now,"dd.mm.yy hh:mm") 

or even better

 .Cells(1, 1) = Now 

then format the column as follows:

 Columns("A:A").NumberFormat = "dd.mm.yy hh:mm" 

Note. It is possible that the presence of mm in the format string did not help, although, having tried it, it seems to work fine.

+8
source

Source: https://habr.com/ru/post/890587/


All Articles