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:

Directory 1 File NamesD1 New File NameDirectory 2 File NamesD2 New File NameDirectory 3 File NamesD3 New File NameMerged File Names
Rename as Cell I12Rename as Cell H11Rename as Cell H8Based on Concatenated Values from Cells I12, D4, E2 from Directory 1 Worksheet
File Names456789PH12345678678PH12345232214PH12345PH12345_A-Class_Denver
124352PH23523786782PH23523654665PH23523PH23523_A-Class_Chicago
465634PH34234544253PH34234425345PH34234PH34234_C-Class_Philadelphia
653634PH25533123213PH25533856658PH25533PH25533_B-Class_Amarillo
736343PH87897924221PH87897324234PH87897PH87897_B-Class_Tucson
Becomes Worksheet1Becomes Worksheet 2Becomes Worksheet 3

<tbody>
</tbody>


Any guidance is appreciated!
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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,213,552
Messages
6,114,278
Members
448,560
Latest member
Torchwood72

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