Renaming folders (from column OldFolderName to NewFolderName)

shuchman

New Member
Joined
Mar 16, 2021
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
This is probably really basic but I'm having a bit of trouble,

I have an excel sheet with 2 columns, one is oldname and the other is newname and I have to rename folders listen in oldname to their matching newname (right next to them, rename a2 -> b2).
The problem is also that there can be a situation where 2 folders from Oldname now have the same name (a2->b2 , a3->b3 where b3=b2) so basically they need to be re-named and merged.

1615889891902.png


I'm not very skilled at VBA and I hope it's not too rude for me to ask for help without at least having some basic input of a code, thank you!
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Zot

Well-known Member
Joined
Nov 26, 2020
Messages
1,170
Office Version
  1. 2016
Platform
  1. Windows
Try this
VBA Code:
Sub RenameMyFolders()

Dim n As Long
Dim OldFolderName As String, NewFolderName As String
Dim objFileSystem As Object

Set objFileSystem = CreateObject("Scripting.FileSystemObject")

' Loop through list name
For n = 2 To 7
    'Path for old folder and renamed folder. Modify to your need
    OldFolderName = "C:\Users\username\Desktop\" & Range("A" & n) & "\"
    NewFolderName = "C:\Users\username\Desktop\" & Range("B" & n) & "\"
    'Check if the folder existed
    If objFileSystem.FolderExists(OldFolderName) = True Then
        'Rename the original folder
        Name OldFolderName As NewFolderName
    End If
Next

End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,129,763
Messages
5,638,215
Members
417,014
Latest member
dualwieldbacon

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
Top