Vba to look for non 0 values and copy them to another workbook

spill-the-beans

Board Regular
Joined
Feb 7, 2013
Messages
52
Hello :) I've learned a little bit from you all to at least try and start my own code, but I'm completely lost this time.

I have a folder with about 120 text files in there. In a header-named column of each text file there are numerical values. I'm trying to create some code that will open every file, look for the non 0 values, and copy the values to another column in another workbook.
  • First, the name of the open text file needs to be copied across in the next empty row of the results file.
  • Then, values should be looked for in the named column of the text file.
  • If a non 0 value is found, it should be copied and pasted into the results book, in the same active row as the pasted name of the file it came from, but the next empty column.
  • If I had 120 text files, each with up to 2 non 0 values in the named column, the results file would end up with 120 rows, with 3 columns (text file name, first found value, second found value).

There can be any number of 0s and up to about 5 non 0s in the column, but to demonstrate:

In file 1, named "Tom_1.Word1"

Result
0
2
0
4

<tbody>
</tbody>


In file 60, named "Tom_60.Word60"

Result
15
17
0
19

<tbody>
</tbody>

In file 120, named "Tom_120.Word120"

Result
0
100
110
0

<tbody>
</tbody>


In another file, the information I need to get out, should be:

FileResult 1Result 2Result 3
Tom_1.Word124
Tom_60.Word60151719
Tom_120.Word120100110

<tbody>
</tbody>

Can anyone help with this please?
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,216,434
Messages
6,130,611
Members
449,584
Latest member
c_clark

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