How to keep the first space in Cell on a .xlt - vba

I worked on an export of data from an ERP to Excel but I encoutered a problem.
When I received my datas on my model Excel (.xlt, i don't have a choice for the extension...), all first spaces of fields in the ERP disappeared on my worksheet...
An exemple (Here, spaces before "Holder") :
And now, on excel, without spaces... :
And the last information, I think the problem is only on file type .xlt (97/03) (The only one I can use of course...) because when I try an export in .xls, there is no problem.
I already tried to change the type of cell in Text or Standard but it doesn't work.
Did you have a solution ?
Thanks !

Let me outline a typical solution:
You have a "data source" you cannot control - in this case it's an xlt file that somewhere on your hard drive - call it export1.xlt
You want to add the data from a data source (export1.xlt) to a "database" which could just be another aggregate spreadsheet or whatever. Let's call it database1.xlsx.
Typcially you would create a marcro inside database1.xlsx that knows how to import data into intself - in this case let's say you give a path e.g. C:\temp\export1.xlt and tell it to copy that data to Sheet1.
When you run that macro it will open export1.xlt, read the data into Sheet1 of database1.xlsx, and perform any necessary post-processing.
In this case the post processing could simply be looping over every cell to looking for a missing space.

Related

Export specific data from a selected cell's row into a CSV file

I have been searching for a solution to this, but it seems like I cannot find it.
So basically, I want to select e.g. H2 and then run the macro.
Then it should copy/paste some specific cells into a new CSV file, e.g. O2 and F2. I also want a fixed value that should always be there, called "No".
The first row of the CSV file should be "UTF-8". The next (2nd row in the CSV) should be some headers that is fixed, just as the UTF-8.
Could a solution be to copy all the relevant data into another sheet with the proper format, and then just export that sheet as a CSV?
Illustration:
"UTF-8"
"Name","ID","Email","Customer"
"H2","O2","F2","No"
Solution ended up being exporting the correct data into another sheet with the proper setup, using the following.
Sheets("Sheet1").Range("XX:XX").Copy Destination:=Sheets("Sheet2").Range("XX")

SQL developer Import data wizard comes up blank

So I have a file that has over 100 entries in it as an excel worksheet. I want to put those over into a sql. So I fire up my sql developer and try and import the data but it doesn't show up.
The next and finish buttons don't do anything. (the blue underline words aren't links to anything either fyi)
Have you tried converting the original file to text (csv) then importing? That has worked for me in the past.
I had the same problem and the only way to get rid of it was to rename the preferences folder (as described here: https://www.thatjeffsmith.com/archive/2015/08/how-to-reset-your-sql-developer-preferencessettings/) and start the program with factory defaults.
One more reason is that the CSV or excel file is of 0 kb size or empty.

vb.NET SaveAs not saving all Excel data

I have a very strange issue that I cannot seem to find an answer to online.
I have a VB.NET application that creates an Excel of data (roughly 42,542 rows in total) and the saves the file to a folder location & opens it on screen for the user.
The onscreen version & folder version is only showing 16,372 rows of data like it is being cut off.
When I go through debug I can see all the rows are being added & if I save manually in debug all the rows save. Some data seems to get lost on the system save.
I am taking data from 4 record sets & writing each set one after the other with specific headers for each block on the Excel sheet.
My save line is:
xlWBook.SaveAs(Filename:=sFileName, FileFormat:=Excel.XlFileFormat.xlExcel7)
Would anyone please have any ideas as to what this might be?
Older version of Excel only support 16,384 rows per worksheet. You are saving as Excel7 (which is Excel 95) and has this limitation:
See here for a summary of sizes per version:
https://superuser.com/questions/366468/what-is-the-maximum-allowed-rows-in-a-microsoft-excel-xls-or-xlsx
Change your code to another format, See here for all the allowed formats: XlFileFormat Enumeration
However the file format is actually an optional argument in the SaveAs method, so you could leave it off altogether: "For an existing file, the default format is the last file format specified; for a new file, the default is the format of the version of Excel being used."
Source: WorkBook.SaveAs Method

excel macro to read text file and find matches in cells

I really could use some help
I have two .txt/csv files that I need to read from into my excel file.
In my excel file I have a whole column, each cell containing string of characters and I need to write a script to be able find matches and and copy an adjacent column from that txt file.
An example of a single row on my txt file is shown below:
"AB101AA","AB10 1AA","AB101A","AB10 1A","AB101","AB10 1","AB10","AB10","AB","10",394251,806376,,
"AB101AF","AB10 1AF","ABERDEEN","ABERDEENSHIRE",,"ABERDEEN, CITY OF"
My excel file would have a cell which probably say "AB101AF" and i want the corresponding cell to run through a million rows and find the match and then find the corresponding nth cell on the txt file and return it on the excel spreadsheet example "ABERDEEN, CITY OF".
I know I havent been helpful in explaining the issue. But any help would be appreciated.
Thank you
Depending upon the size of your text file you could import the file using the GetExternalData option in Excel. This would allow you to load your data into a different Sheet and then use a lookup to your data from the main Sheet. Using Match and/or vlookup should help here.
You could also add a workbook connection to the text file and search using the connection.

Convert xls File to csv, but extra rows added?

So, I am trying to convert some xls files to a csv, and everything works great, except for one part. The SaveAs function in the Excel interop seems to export all of the rows (including blank ones). I can see these rows when I look at the file using Notepad. (All of the rows I expect, 15 rows with two single quotes, then the rest are just blank). I then have a stored procedure that takes this csv and imports to the desired table (this works on spreadsheets that have been manually converted to csv (e.g. open, File--> Saves As, etc.)
Here is the line of code I am using for my SavesAs in my code. I have tried xlCSV, xlCSVWindows, and xlCSVDOS as my file format, but they all do the same thing.
wb.SaveAs(aFiles(i).Replace(".xls", "B.csv"), Excel.XlFileFormat.xlCSVMSDOS, , , , False) 'saves a copy of the spreadsheet as a csv
So, is there some additional step/setting I need to do to not get the extraneuos rows to show up in the csv?
Note that if I open this newly created csv, and then click Save As, and choose csv, my procedure likes it again.
When you create a CSV from a Workbook, the CSV is generated based upon your UsedRange. Since the UsedRange can be expanded simply by having formatting applied to a cell (without any contents) this is why you are getting blank rows. (You can also get blank columns due to this issue.)
When you open the generated CSV all of those no-content cells no longer contribute to the UsedRange due to having no content or formatting (since only values are saved in CSVs).
You can correct this issue by updating your used range before the save. Here's a brief sub I wrote in VBA that would do the trick. This code would make you lose all formatting, but I figured that wasn't important since you're saving to a CSV anyway. I'll leave the conversion to VB.Net up to you.
Sub CorrectUsedRange()
Dim values
Dim usedRangeAddress As String
Dim r As Range
'Get UsedRange Address prior to deleting Range
usedRangeAddress = ActiveSheet.UsedRange.Address
'Store values of cells to array.
values = ActiveSheet.UsedRange
'Delete all cells in the sheet
ActiveSheet.Cells.Delete
'Restore values to their initial locations
Range(usedRangeAddress) = values
End Sub
Tested your code with VBA and Excel2007 - works nice.
However, I could replicate it somewhat, by formatting an empty cell below my data-cells to bold. Then I would get empty single quotes in the csv. BUT this was also the case, when I used SaveAs.
So, my suggestion would be to clear all non-data cells, then to save your file. This way you can at least exclude this point of error.
I'm afraid that may not be enough. It seems there's an Excel bug that makes even deleting the non-data cells insufficient to prevent them from being written out as empty cells when saving as csv.
http://answers.microsoft.com/en-us/office/forum/office_2010-excel/excel-bug-save-as-csv-saves-previously-deleted/2da9a8b4-50c2-49fd-a998-6b342694681e
Another way, without a script. Hit Ctrl+End . If that ends up in a row AFTER your real data, then select the rows from the first one until at least the row this ends up on, right click, and "Clear Contents".