copy multiple different root of source folder to different root of destination

pikapikachiu

New Member
Joined
Feb 24, 2018
Messages
2
i manage to copy from 1 row of source path folder to destination ( B2 to C2)
but i has trouble to write the code to continue loop copying from 2nd row & so on until empty cell value
can anyone help me to fix the code? i need its can loop continue fro ( B3:until end, to C3 until end)
below is the code of me

Sub sbCopyingAFolder()

Dim FSO

Dim sFolder As String, dFolder As String

sFolder = Range("B2").Value ' souces folder

dFolder = Range("C2").Value ' destination folder

Set FSO = CreateObject("Scripting.FileSystemObject")

If Not FSO.FolderExists(dFolder) Then

FSO.CopyFolder sFolder, dFolder

MsgBox "Folder Copied Successfully to The Destination", vbExclamation, "Done!"

Else

MsgBox "Folder Already Exists in the Destination", vbExclamation, "Folder Already Exists!"

End If
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
You can set a value to the last row in your spreadsheet and then use a For/Next loop to cycle through all records. See your revised code below.

Code:
Option Explicit


Sub sbCopyingAFolder()
Dim i As Long
Dim lastrow As Long
Dim FSO
Dim sFolder As String, dFolder As String




lastrow = Cells(Rows.Count, "B").End(xlUp).Row


For i = 2 To lastrow
    sFolder = Range("B" & i).Value ' souces folder
    dFolder = Range("C" & i).Value ' destination folder
    Set FSO = CreateObject("Scripting.FileSystemObject")
    
    If Not FSO.FolderExists(dFolder) Then
        FSO.CopyFolder sFolder, dFolder
        MsgBox "Folder Copied Successfully to The Destination", vbExclamation, "Done!"
    Else
        MsgBox "Folder Already Exists in the Destination", vbExclamation, "Folder Already Exists!"
    End If
Next i


End Sub
 
Upvote 0

Forum statistics

Threads
1,215,883
Messages
6,127,552
Members
449,385
Latest member
KMGLarson

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