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

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.
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
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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