Merge and Rename Worksheets Based on Matching Cell Values

lager1001

Board Regular
Joined
May 17, 2019
Messages
88
Good morning,

I have excel files in directories that I need to rename based on the value in specific cells in each worksheet and need help with a macro code to achieve this. I would like the macro to loop through the folders and rename each file based on the value it finds in the indicated cell. I've been searching through codes but haven't found anything that quite does what I need it to.

I'd like to point the macro to the directory either via navigating to it, or by hard coding the directory path within the macro.

I will be doing this for 3 different directories then merging the newly created files from each directory into 1 workbook based on the newly matched file names. The file from Directory 1 becomes Worksheet 1 of the newly merged workbook, the file from Directory 2 becomes Worksheet 2, etc.

See below table for an example:

456789PH12345678678PH12345232214PH12345PH12345_A-Class_Denver
124352PH23523786782PH23523654665PH23523PH23523_A-Class_Chicago
465634PH34234544253PH34234425345PH34234PH34234_C-Class_Philadelphia
653634PH25533123213PH25533856658PH25533PH25533_B-Class_Amarillo
736343PH87897924221PH87897324234PH87897PH87897_B-Class_Tucson

<tbody>
[TD="width: 152, bgcolor: #B2B2B2"] Directory 1 File Names [/TD]
[TD="width: 144, bgcolor: #B2B2B2"] D1 New File Name [/TD]
[TD="width: 150, bgcolor: #B2B2B2"] Directory 2 File Names [/TD]
[TD="width: 141, bgcolor: #B2B2B2"] D2 New File Name [/TD]
[TD="width: 149, bgcolor: #B2B2B2"] Directory 3 File Names [/TD]
[TD="width: 145, bgcolor: #B2B2B2"] D3 New File Name [/TD]
[TD="width: 533, bgcolor: #B2B2B2"] Merged File Names [/TD]

[TD="bgcolor: #B2B2B2"][/TD]
[TD="bgcolor: #B2B2B2"][/TD]
[TD="bgcolor: #B2B2B2"] Rename as Cell I12 [/TD]
[TD="bgcolor: #B2B2B2"][/TD]
[TD="bgcolor: #B2B2B2"] Rename as Cell H11 [/TD]
[TD="bgcolor: #B2B2B2"][/TD]
[TD="bgcolor: #B2B2B2"] Rename as Cell H8 [/TD]
[TD="bgcolor: #B2B2B2"] Based on Concatenated Values from Cells I12, D4, E2 from Directory 1 Worksheet [/TD]

[TD="bgcolor: #B2B2B2"] File Names [/TD]

[TD="bgcolor: #B2B2B2"][/TD]

[TD="bgcolor: #B2B2B2"][/TD]

[TD="bgcolor: #B2B2B2"][/TD]

[TD="bgcolor: #B2B2B2"][/TD]

[TD="bgcolor: #B2B2B2"][/TD]
[TD="bgcolor: #B2B2B2"][/TD]
[TD="bgcolor: #B2B2B2"]Becomes Worksheet1[/TD]
[TD="bgcolor: #B2B2B2"][/TD]
[TD="bgcolor: #B2B2B2"]Becomes Worksheet 2[/TD]
[TD="bgcolor: #B2B2B2"][/TD]
[TD="bgcolor: #B2B2B2"]Becomes Worksheet 3[/TD]
[TD="bgcolor: #B2B2B2"][/TD]

</tbody>


Any guidance is appreciated!
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Re: HELP - Merge and Rename Worksheets Based on Matching Cell Values

Why rename first, then merge? Why not merge straight away using the correct names for the sheets?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,173
Members
453,021
Latest member
Justyna P

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