Skip to content
Advertisement

Wrong data types when loading sql query with vba in excel

I have a SQL Query, which I want to use in VBA to load the data into Excel, the problem is that when the load is done the data in Excel is with the wrong type. For example, where it needs to be a date, it remains an integer, where an integer is a date. Is there any way to fix this? Example my query:

sql = " SELECT DATA, ITEM, COMPANY, SALES FROM SALES "

Advertisement

Answer

You will have to format cells as per date format. Also ensure that values are correct in your query output.

Sheet1.Range("A2", "A100").NumberFormat = "yyyy-mm-dd"
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement