VBA Code to Rename Folders

npm94

New Member
Joined
Jun 18, 2015
Messages
1
Hi all, I just started teaching myself VBA this past week. Currently, I'm trying to write a code that pulls information from cells in Excel to rename a folder. My excel worksheet looks like this:

Column A: Source of Folder Path
Column B: Source of Folder Path NEW

This is the code that I've found/developed--the name statement seems to work, but I don't know how to loop it or make it pull information from excel.

Sub FolderRename()
'Declaring variables
Dim complete_pathof_folder As String, state As String
'Variable values
complete_pathof_folder = Cells(2, 2)
state = Cells(2, 5)
'Renames Original Folder Name
Name "C:\Users\n0269632\Desktop\Customers\AFL TELECOMMUNICATIONS" As "C:\Users\n0269632\Desktop\Customers\AFL TELECOMMUNICATIONS (SC)"
'Repeats Code Until an Empty Cell is Reached
Do Until IsEmpty(Cells(iRow, 1))
dCellValues(iRow) = Cells(iRow, 2).Value
iRow = iRow + 1
Loop
End Sub



I believe the Dim code would pull information from excel and the loop function would loop it--obviously--but I don't know where to put it. Any help would be truly appreciated. Thank you!
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hi and welcome to the Board

Please test this:

Code:
Sub RenameFolders()
Dim i%                                  ' current path at column A
i = 1                                   ' new path at column B
While Not IsEmpty(Cells(i, 1))
    Name Cells(i, 1) As Cells(i, 2)
    i = i + 1
Wend
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,628
Messages
6,179,981
Members
452,952
Latest member
sravani A

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