Data Copy using Excel-VBA - excel

I am having a folder of 10 excel-based CSV files. Is there any method to copy the data from all these files into 1 excel
Not good with VBA, so thought to ask you guys

On a first sight, I would go for the following approach (coming up with the codes is up to you, Google is your friend):
Get a list of all file names within that directory
Iterate over every item from the above list and open the file with Workbooks.Open(...)
Copy the whole content and paste it to the additional Excel you want to manage to hold the data of all files
Repeat the steps for each file
Remember to save the last row after every paste s.t. you can continue with amending the data into the addtional Excel instead of replacing the content.

Related

Extract data corresponding to an ID in excel (VBA - Excel)

I'm having 2 excel files, one big file contains all data, and the second one is smaller and filter manually. They can be like this:
BIG EXCEL FILE
ID ------- Infor
123------ABC
134------BCD
SMALL EXCEL FILE
ID-------Infor
123------...
333-----...
So if I want to fill in the small excel file, I have to copy the ID, paste into the big file, copy the data of that ID, then paste into the small file.
Can you help me to develop a VBA that can automaticallly find same ID and paste data next to it?? I suppose that we can merge 2 file excels together for easier implementation.

How to combine multiple Excel files?

I have multiple Excel files in the same format and I want to combine them into a single file.
How can I merge them into one single excel file using VBA?
VBA is no longer required to merge files. You can use Power Query and merge all files in the same folder with just a few clicks. When the files change, you just update the query.
You have two choices:
a "flat" file, in which all the data are in a single sheet (BAD)
A multi-sheet file (GOOD)
In the first case open a new file, cut and paste your existing content into the new (single) sheet
In the second case Move/Copy the sheets to a New Document.
There: you now have enough Google fodder to get you started.
I had this same issue a while back and found an excellent solution thanks to my good friend Google. All credit for this solution goes to the following page: computer hope
To merge Microsoft Excel files together, save them as CSV files first (it would be possible to automate this part in VBA if there is a recurrent need). Open the Excel files and in the menu bar, click File, then Save As. In the Save as type drop-down list, select CSV (comma delimited) (*.csv) from the list.
Do this for each Excel file you want to merge, then place all the CSV files in the same folder. For ease, place them in a folder in the root of the C: drive (e.g., c:\csvfiles).
Open the Windows command prompt (to get to this, in the Search or Run line, type cmd and press return) and navigate to the folder containing the CSV files. Type dir to view the files in the folder and ensure all the files are there.
Type in the following command to merge all CSV files in the folder into a new CSV file titled "newfile.csv" (any name could be used):
copy *.csv newfile.csv
After the new file is created, open the new CSV file in Microsoft Excel and save it as an Excel file.

Batch save pictures from multiple excel files in a folder

I have about 10000 excel files, that in a specific cell of all of them there is a picture. I need a script to read all files and save the picture with the same name of the excel files in a folder.
Could you please help with that?
Thanks.
This method is based on a number of assumptions:
All the files (10000) are located in a know folder,
All files are named according to a paradigm that can be reproduced programmatically (if not, you can get the list of files within the folder, store the list within an array, and loop through the array),
Pictures are always within the same worksheet or, if in more than one, the names of the worksheets can be reproduced programmatically,
The filenames to be used to save the pictures can match (at least as a seed) the one of the Excel the pictures are extracted,
You will manage to write some basic VBA.
Note that for the VBA you have at least two options:
Write it within an EXCEL that will only serve as the extraction engine, or
Write it as a stand-alone file and run it via DOS commands.
The VBA logic:
Create the outer loop that processes a single file,
Within the outer loop, generate the name of a file to be open,
Open the file using Workbooks.Open VBA function,
Select the worksheet and the cell containing the picture,
Use the Workbook.SaveAs to save the picture (you will need to specify the type of file to be used, e.g. .bmp).
As a simple and very efficient tool to get the code (at least) partially generated by Excel, you can RECORD a MACRO for each action and then stop recording. You will see the code generated (you will need to access the VBA mode). You can copy-paste the generated code into your development (you might need to do some simple adaptations though).
That's it.
Hope you manage. Good luck!!

Excel Save CSV without blanks

I have an Excel spreadsheet that generates CSV scripts used in an application. The scripts must be in a very specific format, and I save a master in XLSX format with protected sheets and data validation to save the CSVs from rather than directly edit the CSVs, as directly editing the CSVs can lead to mistakes.
The issue is that the scripts can be of nearly any length. The left column of each line can only be one of a certain set of values, and the last line has to say "END". The only way I can do this without VBA is the following formula in the A column, from row 7 (the first 6 are header information) to row 1048576 (last Excel row) and protect the sheet with column A locked:
=IF(AND(ISBLANK(B368),NOT(ISBLANK(B367))),"END",IF(ISBLANK(B368),"",A367))
This makes the last row say "END" in column A, and all rows after blank, which is what is desired. The problem is that now when the CSV file is saved, it will always have 1048576 rows, with all the bottom rows containing the delimiters ",,,," . This won't work, the CSV file needs to stop after the "END" row. Is there a way to write the formula that will cause Excel to ignore the cells which evaluate to blank when saving to CSV or an alternate way to save to CSV in Excel that will ignore all the rows that evaluate to blank?
Note: I have a solution in VBA already that I can use on my own machine (it copies the data up to "END", pastes in a new sheet in text only format, then saves as CSV with the name of the original worksheet). I want to share this sheet, however, and getting around the security constraints to share macros at my company is a pain. So I'm looking for a way this might be done without Macros, if it's possible at all.
In looking for an answer I found this link, which is similar, but not the same:
Saving Excel data as csv with VBA - removing blank rows at end of file to save
As the "blanks" I have are active rows because they contain formulas, this method will not work.
Manually deleting the rows / columns will work to reset the size, as GSerg noted in the other question. Alternatively, also as suggested by GSserg, you can copy the data to a new sheet before saving.
Otherwise, an easy fix might be to create a small post-excel / pre-processing script - perhaps using a batch file - Batch / Find And Edit Lines in TXT file - or a similar solution in any small scripting language to remove the extra rows.

Copy data from Excel to Word

I have a .csv file which I can export and from which I need to copy data into word.
I know how to get the relevant data from Excel and format my .csv file with VBA, however I don't know how to get my data from that Excel file to Word.
Basically this is how a line of my formatted .csv file looks (I Got rid of all the info I don't need).
For clarification: 1st long nr. is personnel 2nd one is token.
And I need to fill that info into the following table in word (Not everything gets filled in).
And one extra thing, depending on the extention of the email address #mc or #lmc, I need a different file opened (Different languages). How would I best do that?
Possible algorithm:
In your Excel document, develop a VBA macro that
Copy data/elements from Excel document
Open your word document
Paste excel data to word document (to the places you want)
Save word document
Close word document
Here is some code for inspiration of how to do that.

Resources