Number format in CSV file - excel

I've got a macro that imports data from a SQL db to excel then saves the results as a CSV file. When it saves to CSV the formatting of two of the columns is lost, resulting in the numbers not displaying correctly.
Column 1 contains 12 digit numbers such as '800000000000' which are showing in the CSV file as '8E+11'
Column 2 contains 10 digit numbers such as '4880000000' which are showing in the CSV file as '4.88E+09'
The data displays fine when it is first imported to excel, the problem occurs when saving to CSV, although when I expand column 2 in the CSV file it displays the full number. This doesn't work for column 1 though, I have to change the formatting of the cell.
I usually run the macro then send the created CSV file on to a colleague, is there a way I can keep the number formatting without having to open and edit the CSV file?
Thanks

Adding "=" before the quotes preserves the pattern
For Example if your csv file is like
A1,col1,col2,col3,="001"
The 5th column will still be 001 when opened in excel

Related

Folder with multiple .csv files. Want from each .csv file to get last row into one excel file

Hello as the title says..
I have in a folder multiple .csv files and I am looking for a method to get from each .csv file the last row and insert it into one main excel .xlsx file.
Each .csv file has the same amount of "columns", but different amount of rows.. Well by columns is meant that the same amount of values in the first cell.
Also, as the separator a comma is used..
Thank you in advance!

Excel keeps changing my text values to date in my CSV file

I have an exported CSV file that needs to be reimported.
It has an address column having data like -
01-03, 08-01, 01-05
Upon opening the file in excel, it reads these values like dates.
I changed the column format to text after extracting the values into text as =TEXT(column,"dd-mm") and pasting the values, which shows the correct value 01-05.
However, when I close and re-open the file they are converted back to Dates again as 16-Mar, 01-May etc.

How to Append CSV file via VBA without reading empty formatted cells

I have a code that is able to Append a range of data in a worksheet to an existing CSV file. However, I noticed that when the existing CSV file contains empty, but formatted cells beyond the end of the data range, the Append function takes into account those empty cells as well.
For example, the existing CSV file has 10 rows of data, while rows 11 to 20 are empty, but has been formatted (e.g. as "dd-mmm-yy"). So when I append the CSV file, the new data is added at row 21 instead of row 11.
Apart from manually deleting rows 11 to 20 in the CSV file, is there a quick fix to this? I have many existing CSV files, so it is not feasible to do the manual way. As to why some of the rows are empty, but formatted, it is due to some earlier amendments that took place.
Appreciate the help.
I have a code that is able to Append a range of data in a worksheet to an existing CSV file. However, I noticed that when the existing CSV file contains empty, but formatted cells beyond the end of the data range, the Append function takes into account those empty cells as well.
If you've written that code, it needs to account for the formatted cells you want to ignore. Let's say you're exchanging data from a .xlsx file to a .csv file and all of this is being done inside the Excel platform. Then for example, if "General" is the format that works best for you, but some trailing cells in .csv column A, Sheet 1 are not that, then have your code evaluate on a loop whether CSV Worksheets("Book1").Range("A[whatever row]").NumberFormat = "General"
Then have your code change the ones that aren't, to General; then proceed with the append.

My .xls document is opening in apple numbers with all of the data in one column

I've got a document written in vbscript that generates a .xls document. In the code the data is separated by vbtab's. It opens normally in excel, but in apple numbers all of the data is in one really wide column with the data separated with tabs, as in several spaces. It looks fine, but I need the data to be in different columns so that it can be sorted. Any ideas?
According to Apple, Numbers can import the following formats:
Numbers ’08 or later
Microsoft Excel - Office Open XML (.xlsx) and Office 97 or later (.xls)
Comma Separated Values (CSV)
Tab-delimited text files
It's likely that the issue is that your "xls" file isn't actually Excel formatted. Try changing the file extension of the output file to .txt and opening it in Numbers.
Depending on your data, I would recommend you just output csv instead.

Dot at end of numbers in CSV file

I have an excel file with some numbers followed by a dot, say:
12345.
I created a simple macro to convert and save the excel file into a .csv file.
The problem is the CSV file does not save the dot. The data comes out as 12345 and not 12345. I also tried manually adding the dot and saving the csv file, but the dot just dissappears.
Anyway to add the dot into the CSV file?
http://i.stack.imgur.com/UoboK.jpg
Add a single quote/apostrophe in front of the number (without a closing quote at the end), so that it reads it as text and does not auto-format it as number.
For example you have:
12345.
Excel will auto-format that column as a number and drop the period unless you specify that it's a text only column.
Change it to:
'12345.
Excel will read that value as a text column and will not save the apostrophe in a text-based CSV file.
Edit:
In testing this, I found that ff you save it as "12345.", Excel changes the CSV file to """12345.""".

Resources