none
Excel does not preserve format from SQL when using Query: RRS feed

  • Question

  • Excel does not preserve format from SQL when using Query:

    Hi in my VBA Code, I am using sql query: select * from abc

    and priniting result in sheet2

    and every time result will be different( in same sheet2: query will be different i.e select x,y,z from xyz)

    so format getting changed for the output(i.e for date it is giving different value and in some value column it is giving #)

    I cannot use format and then general coz there are multiple columns and multiple sheets.

    please suggest what needs to be done in code to keep the format as it is.

    did so much search but didn't found any answer.

    Thursday, May 19, 2016 1:47 PM

Answers

All replies

  • Please reply
    Friday, May 20, 2016 8:41 AM
  • Hi Prapti Deshmukh,

    Please provide the code and data in Excel.

    I'll move your question to the MSDN forum of Excel for Developers

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=exceldev

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.


    Regards,

    Emi Zhang
    TechNet Community Support


    Please mark the reply as an answer if you find it is helpful.

    If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Friday, May 20, 2016 8:49 AM
  • Hi Emi, Where to attach excel file as I am not getting any option for attachment in this reply box

    Friday, May 20, 2016 10:41 AM
  • Just record a small macro to apply formatting after the import is done.

    MY BOOK

    Friday, May 20, 2016 11:38 AM
  • Hi Prapti,

    Did the suggestion from ryguy work for you? If you manually format the date in excel sheet, will it meet your requirement?

    >> I am using sql query: select * from abc and priniting result in sheet2 and every time result will be different( in same sheet2: query will be different i.e select x,y,z from xyz)

    How did you print result in sheet2? It would be helpful if you could share us your key code. You could upload your file to onedrive and then share us the link.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, May 23, 2016 5:59 AM