Problem with data format in Excel
Hi, I am moving some data from an Access database to an Excel file with:
VB Code:
oXLSheet.Range("A2").CopyFromRecordset rstExcel
I am having some troubles with the format data is displayed. With the columns that are "Date/Time"data type in the Access database I put:
VB Code:
oXLSheet.Columns("A:A").NumberFormat = "dd/MM/yyyy hh:mm:ss"
in the visual basic code to move them in the correct format, and it works ok. But there are other columns that are "Number" data type in Access and when I move them to an excel file they appears like "27/02/1900"
(I think 00/00/1900 corresponds to 0). I don´t understand why the program considers this data as dates instead of numbers. I have tried:
VB Code:
oXLSheet.Columns("B:B").NumberFormat = "0"
but it doesnt work. How could I get the data in the correct format? I have other columns in Access that are "Number" data type and they appear correctly in the Excel file :confused: Thank you very much for your help!!
Re: Problem with data format in Excel
Moved to Office Development
What kind of values are in the column(s) that arent shown properly?
What happens if you try this format instead:
VB Code:
oXLSheet.Columns("B:B").NumberFormat = "General"
Re: Problem with data format in Excel
I have tried what you said:
VB Code:
oXLSheet.Columns("B:B").NumberFormat = "General"
but the data is displayed again in the "27/02/1900" format. The values in these columns (I have 2 problematic columns) are numbers (positive integers), I can see them correctly if I open the Access database. In the table design the data type for these 2 columns is "Number". The most annoying thing is that I have other columns with the same data type and they are shown correctly in Excel. Moreover, sometimes the 2 problematic columns are shown correctly, but other times no (I don´t know why) so I would like to force these data to be displayed always in the correct data format if possible. Thanks for your help!!