Combining lines from several files within folder via IF or similar

Michael1984DK

New Member
Joined
Apr 30, 2018
Messages
27
Hi.

I have a need to make a script, that opens and looks through all files within a selected folder. In each file, it should look for a certain IF sentence. If the cell in the line of the specific file = TRUE, it should copy these lines to a new file. The idea is to add and collect all the "valid" lines into one file in continued order (so copy to first empty line or where cell x = "").

I already have a VBA script, that opens each file with a user selected folder, but I am not sure how to do the last part for each file (the action itself).

I think it would be easiest to have a "summary file" containing the "open all files and do action" script within. This should also be the file to copy the valid lines from the other files into.

Ex:
File 1:
No
No
No
Yes - Copy to summary in first empty line
Yes - Copy to summary in first empty line
No
Yes - Copy to summary in first empty line

File 2:
Yes - Copy to summary in first empty line
Yes - Copy to summary in first empty line
No
No
Yes - Copy to summary in first empty line
No

Summary..
Yes (from file 1 line 4)
Yes (from file 1 line 5)
Yes (from file 1 line 7)
Yes (from file 2 line 1)
Yes (from file 2 line 2)
Yes (from file 2 line 4)

Does this make sense and can it be done somehow?

Thank you.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
I tried the macro with the files you posted and it worked properly so I don't know why it is not working for you. Try stepping through the macro one line at a time using the F8 key. Each time it opens one of the source files and copies the data, check back to that "Overview" sheet and see if the range has been copied (it will have a flashing border around it). Then execute the "pastespecial" line of code and check if it has been pasted to the "Summary" sheet. Maybe by stepping through the code one line at a time, you will be able to see where it breaks down.
 
Upvote 0
Hi again. I tried going through the script with F8, opening all files one by one. It does all that it is supposed to with file 1, but the following, it opens them, doesnt seem to do anything, then closed them again. Could I have disabled some setting allowing them to be run when running some other script where this setting wasnt "turned back on" at the end of the script?

I have tried other pieces of script that I found online before making this thread and those could open and copy from several but just didnt select only the lines I wanted. Instead it took f.ex. everything from line 6 to 40 and copied them, but I only mention this as it seems it can indeed do the multiple files job. I am confused. :)
 
Upvote 0
Update. :)

I got it to work by trying to clear the Summary sheet in the "master file". So it seems that the existing summary sheet was causing it not to work properly? Maybe some small prefilled out formula in a cell that I didn't notice.

So great news, my computer can indeed do the job, just me who didn't check everything ahead. My apologies for this. :)

Thank you so very much for you help on this! :)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,922
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top