Merge and Rename Worksheets Based on Matching Cell Values

lager1001

Board Regular
Joined
May 17, 2019
Messages
77
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!
 

Some videos you may like

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

sijpie

Well-known Member
Joined
Nov 1, 2008
Messages
3,734
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?
 

Watch MrExcel Video

Forum statistics

Threads
1,118,168
Messages
5,570,621
Members
412,333
Latest member
hectamuptra
Top