• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Duplicate files move to Duplicate folder

Abhijeet

Active Member
Hi
I have macro to identify Duplicate files i put formula for this with Same Size of file is duplicate.I want all Duplicate status that is in Column F file move in Duplicate folder in same Folder to Create & move the files please tell me how to do this
 

Attachments

  • Pdf Duplicate_Macro.xlsm
    30.7 KB · Views: 5
Hi
Luke M i go through this site but i want if in Column F is shown Duplicate then those files move to Duplicate folder not every files i want to move so please tell me
 
Put a If statement in your macro to check the cell's contents. I know we've shown you how to do that before. Remember, it's better if you learn how to do these things then repeatedly asking others to do them for you. Be bold, and try your hand at figuring out what the macro should say.
 
Hi Luke M
I tried to do this i did put filter for show Duplicate data then i stuck i do not know how to define Range of those cell where is file name mention.Please tell me
 
As a reminder would do something like:
Code:
For i = 1 to 100
     if cells(i,"B").Value = "Duplicate" Then
          'Move file
     End If
Next i
 
Hi Luke M
I am doing this but problem is all files are move to duplicate folder please help

Sub FileDetails()
Application.ScreenUpdating = False
'Sheets("Sheet1").Unprotect Password:="Swami"
Dim objfso As Object, myFolder As Object, myFile As Object
Dim strFldName As String
Dim i As Integer
Dim rng As Range
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim FileExt As String
Dim FNames As String

'\\ Get folder browser
On Error Resume Next
'strFldName = CreateObject("Shell.Application").BrowseForFolder(0, "Browse Folder", 0, "").Self.Path
Application.FileDialog(msoFileDialogFolderPicker).Show
strFldName = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1)
On Error GoTo 0

'\\ Don't process further
If strFldName = "" Then
MsgBox "No Folder selected!", vbExclamation
Exit Sub
End If

Set objfso = CreateObject("Scripting.FileSystemObject")
Set myFolder = objfso.GetFolder(strFldName) ' change the folder path

If myFolder.Files.Count > 0 Then
i = 2
For Each myFile In myFolder.Files
Range("A" & i).Value = myFile.Name
Range("B" & i).Value = myFile.DateLastAccessed
Range("C" & i).Value = myFile.DateLastModified
Range("D" & i).Value = myFile.Type
Range("E" & i).Value = myFile.Size
i = i + 1
Next
Else
MsgBox "No files in the specified Folder", vbOKOnly, "No files"
Application.ScreenUpdating = True
End If
Application.ScreenUpdating = False
Set rng = Sheet1.Range("E2:E" & Sheet1.Range("A65536").End(xlUp).Row).Rows
rng.Offset(0, 1).Formula = "=IF(E2=0,"" "",IF(COUNTIF(E:E,E2)>1,""Duplicate"",""Not Duplicate""))"
For i = 1 To 100
If Cells(i, "F").Value = "Duplicate" Then

FromPath = "C:\Users\swami\Desktop\PDF" '<< Change
ToPath = "C:\Users\swami\Desktop\PDF\" & Format(Now, "yyyy-mm-dd h-mm-ss") _
& " Duplicate" & "\" '<< Change only the destination folder

FileExt = "*.*" '<< Change
'You can use *.* for all files or *.doc for word files

If Right(FromPath, 1) <> "\" Then
FromPath = FromPath & "\"
End If

FNames = Dir(FromPath & FileExt)
If Len(FNames) = 0 Then
MsgBox "No files in " & FromPath
Exit Sub
End If

Set FSO = CreateObject("scripting.filesystemobject")

FSO.CreateFolder (ToPath)

FSO.MoveFile Source:=FromPath & FileExt, Destination:=ToPath
MsgBox "You can find the files from " & FromPath & " in " & ToPath
'Move file
End If
Next i
'Sheets("Sheet1").Protect Password:="Swami"
Application.ScreenUpdating = True
End Sub
 
...all files are move to duplicate folder
ok...is this bad? Good? Unexpected?
Also, this code doesn't look anything like what I posted a link to. Your code uses Folder objects, while the linked code used a simple move.

Try to keep things simple, tackling the basic problem of moving files before trying to get more complicated.

Finally, as a note of caution, it appears you either are just grabbing code from different places w/o understanding how they fully work, or you understand the more complex code and knew there was more going on in this problem, but failed to mention it at the beginning of thread. :(
 
Abhijeet,

Please post some sample data for the file posted at post#1. We can't guess your data.

Also are these files in one directory?

Where is the directory path?
 
Its working but every time for duplicate folder give path in Code can u please tell me In same folder Create the duplicate folder
 
Back
Top