Code To Open Files Within Folder Make Changes And Close

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,748
Office Version
  1. 365
Platform
  1. Windows
I need a code that will open dozens of files within a folder in my desktop and if what is found in column A in the active sheet in column AG in each file then it needs to be changed to what is in column B as below. Thanks

Excel 2010
AB
1Column AGChanges To
2CentreCentre
3Centre-LHLH Centre
4Centre-RHRH Centre
5FRFR
6FR Inner-LHFR LH Inner
7FR Inner-RHFR RH Inner
8FR Lower-LHFR LH Lower
9FR Lower-RHFR RH Lower
10FR Outer-LHFR LH Outer
11FR Outer-RHFR RH Outer
12FR UpperFR Upper
13FR Upper-LHFR LH Upper
14FR Upper-RHFR RH Upper
15FR-DSFR DS
16FR-InnerFR Inner
17FR-LHFR LH
18FR-OuterFR Outer
19FR-PSFR PS
20FR-RHFR RH
21InnerInner
22Inner-LHLH Inner
23Inner-RHRH Inner
24LHLH
25OuterOuter
26Outer-LHLH Outer
27Outer-RHRH Outer
28RHRH
29RRRR
30RR Inner-LHRR LH Inner
31RR Inner-RHRR RH Inner
32RR LH+RHRR LH+RH
33RR-InnerRR Inner
34RR-LHRR LH
35RR-OuterRR Outer
36RR-RHRR RH

<colgroup><col style="width: 25pxpx"><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1
So looking at row 3 if Centre-LH is found in column AG of any of the files then it needs to change it to LH Centre, save and close each file and so on...
 
Last edited:
I have tried it on 3 more of my large files and it worked perfect! Could there be something in the files that it dosen't work on thats stopping it? If there was it would error out wouldn't it? This could indicate something wrong on these files that I don't know about and I need to change.
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Sounds like good news/bad news.

Short of sending me a link to a bad file in a PM so that I can see what's breaking it down, I have not a clue.
 
Upvote 0
The first part of the code worked well on most of my files, some I had to make a few changes to manually. For some reason the second part just won't work as needed. Would it be possible to do a code for the second part of the code separately? So in other words I have the list of words in column A it needs to look for in each file in AG. Any words it finds that is not in the list then that needs to be listed (just one of each) and the file name. It may work better with these large files without the first part of the code. I appreciate I have taken up a lot of your time and understand if you want to take it no further. Thanks.
 
Upvote 0
If you didn't need the reporting of unmatched words then I would have suggested that the first part be done by looping through A & B and just doing a find and replace within AG of the second file. However that is irrelevant because you do want the reporting and because the reporting is of words that exist in the second file that are not in the found in the search list in A, the current approach is appropriate.
I don't see splitting the code into two parts being of any benefit. It would certainly double the run time as it would need two loops through the data in AG. In the first run A items in AG would be replaced with B Items. in the second run it would have to to look for the non-existence of B items in AG. So other than searching on B rather than A, I would not see the coding approach for a separate second part being any different from that being used now with the two parts combined so cannot imagine that it will help.
 
Upvote 0
If you didn't need the reporting of unmatched words then I would have suggested that the first part be done by looping through A & B and just doing a find and replace within AG of the second file. However that is irrelevant because you do want the reporting and because the reporting is of words that exist in the second file that are not in the found in the search list in A, the current approach is appropriate.
I don't see splitting the code into two parts being of any benefit. It would certainly double the run time as it would need two loops through the data in AG. In the first run A items in AG would be replaced with B Items. in the second run it would have to to look for the non-existence of B items in AG. So other than searching on B rather than A, I would not see the coding approach for a separate second part being any different from that being used now with the two parts combined so cannot imagine that it will help.

Ok, its just I have run the first part of the code and changed all data that needs to be changed in each file. The second part of the code is to let me know if there and anomalies left that shouldn't be in there and need to be changed, without having to open each file individually do a sort etc etc.

No problem though and thanks very much for your time and efforts.
 
Upvote 0

Forum statistics

Threads
1,215,256
Messages
6,123,906
Members
449,132
Latest member
Rosie14

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