问题
I have a data set in MS Excel 2013 which looks like this:
+------+------------+----------------+
| Name | DateWorked | HoursCompleted |
+------+------------+----------------+
| abc | 03/01/2016 | 4:53 |
| abc | 03/02/2016 | 5:22 |
| ghi | 03/03/2016 | 2:10 |
| jkl | 03/04/2016 | 5:30 |
| mno | 03/05/2016 | 4:20 |
| pqr | 03/06/2016 | 0:20 |
+------+------------+----------------+
where Name
is string, DateWorked
is mm/dd/yyyy, HoursCompleted
is h:mm data type/format.
I am using ADODB to get some results out this data, storing it in a ADODB.Recordset and displaying in another sheet.
My code/query looks something like this:
countCommand.CommandText = "SELECT SUM([HoursCompleted]) FROM [Sheet1$] WHERE [Name] = 'abc' AND [DateWorked] BETWEEN #02/28/2016# AND #03/02/2016#"
Set countResults = countCommand.Execute
Now this works like a charm and gives me a result of 10:15
.
However if the first value under DateWorked
is NOT a Date
datatype then I am not getting the result. For example, if my data looks like this:
+------+------------+----------------+
| Name | DateWorked | HoursCompleted |
+------+------------+----------------+
| abc | Not worked | 0:00 |
| abc | 03/02/2016 | 5:22 |
| ghi | 03/03/2016 | 2:10 |
| jkl | 03/04/2016 | 5:30 |
| mno | 03/05/2016 | 4:20 |
| pqr | 03/06/2016 | 0:20 |
+------+------------+----------------+
How do I set the datatype for my columns?
来源:https://stackoverflow.com/questions/36307625/excel-vba-adodb-datatype-selection