Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel: Run-Time Error '13' Type Mismatch

Tags:

excel

vba

What could be the reason, that I get the the Run-Time Error '13' Type Mismatch with this line of VBA Code:

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

The problem is, that a colleague doesn't get this error. We have both a "German" office.

like image 792
Elmex Avatar asked Jun 15 '11 08:06

Elmex


People also ask

How do you solve a run-time error 13 type mismatch?

Scan for malware or for viruses. Try to start your antivirus and check the system; this may be the reason for the runtime error 13 type mismatch. Just before starting the scan, make sure that your antivirus is updated and functions well. The result of the procedure depends on it.

What is error 13 Excel?

However, this error can still occur and has the following causes and solutions: Cause: The variable or property isn't of the correct type. For example, a variable that requires an integer value can't accept a string value unless the whole string can be recognized as an integer.


1 Answers

I'm not sure why you need the format, since its just being turned straight back into a Date before you fill the cell.

You should really either 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: Its possible that having the mm in the format string could not help, although having just tried it out it seems to work ok.

like image 195
Jon Egerton Avatar answered Oct 20 '22 00:10

Jon Egerton