Merge and Rename Worksheets Based on Matching Cell Values


New Member
May 17, 2019
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
Becomes Worksheet1Becomes Worksheet 2Becomes Worksheet 3


Any guidance is appreciated!


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

Forum statistics

Latest member

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...