0

Below mentioned code successfully copies the file based on source names mentioned in excel sheet using moveFilesFromListPartial, it works perfectly well. i just need one change in the code.

e.g. in excel sheet a source name is written as "Robert Anderson" However if a file with incorrect spelling like "Robert Andersonn" or "Robertt Anderson" comes into source folder, these file with incorrect spelling should get copy in another folder (e.g. Error Folder). In other words files whose exact source name is not in excel sheet should get copy to another folder rather than the destination folder. This way at the end of day we can identify which file names have spelling mistakes and we can simply correct them without reviewing all the files.

currently these kind of files remain stuck in source folder and because of incorrect file name they do not get copy, and i have added another macro which after some times moved the file from Source folder to Archive folder.

Sub moveFilesFromListPartial()
   
 Const sPath As String = "E:\Uploading\Source"

    Const dPath As String = "E:\Uploading\Destination"

    Const fRow As Long = 2

    Const Col As String = "B", colExt As String = "C"
    

    ' Reference the worksheet.

    Dim ws As Worksheet: Set ws = Sheet2
    

    ' Calculate the last row,

    ' i.e. the row containing the last non-empty cell in the column.

    Dim lRow As Long: lRow = ws.Cells(ws.Rows.Count, Col).End(xlUp).Row
                
    ' Validate the last row.

    If lRow < fRow Then

        MsgBox "No data in column range.", vbCritical

        Exit Sub

    End If
    
    ' Early Binding - needs a reference

    ' to 'Tools > References > Microsoft Scripting Runtime' (has intelli-sense)

    Dim fso As Scripting.FileSystemObject

    Set fso = New Scripting.FileSystemObject

    ' Late Binding - needs no reference (no intelli-sense)

    'Dim fso As Object: Set fso = CreateObject("Scripting.FileSystemObject")

   
    ' Validate the source folder path.

    Dim sFolderPath As String: sFolderPath = sPath

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

    If Not fso.FolderExists(sFolderPath) Then

        MsgBox "The source folder path '" & sFolderPath _

            & "' doesn't exist.", vbCritical

        Exit Sub

    End If
    
    ' Validate the destination folder path.

    Dim dFolderPath As String: dFolderPath = dPath

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

    If Not fso.FolderExists(dFolderPath) Then

        MsgBox "The destination folder path '" & dFolderPath _

            & "' doesn't exist.", vbCritical

        Exit Sub

    End If
    
    Dim r As Long ' current row in worksheet column

    Dim sFilePath As String

    Dim sPartialFileName As String

    Dim sFileName As String

    Dim dFilePath As String

    Dim sYesCount As Long ' source file moved

    Dim sNoCount As Long ' source file not found

    Dim dYesCount As Long ' source file exists in destination folder

    Dim BlanksCount As Long ' blank cell

    Dim sExt As String    'extension (dot inclusive)

   
For r = fRow To lRow

    sPartialFileName = CStr(ws.Cells(r, Col).Value)

    sExt = CStr(ws.Cells(r, colExt).Value)
   
    If Len(sPartialFileName) > 3 Then ' the cell is not blank
   
     ' 'Begins with' sPartialFileName
   
     sFileName = Dir(sFolderPath & sPartialFileName & "*" & sExt)
   
     Do While sFileName <> ""
   
         If Len(sFileName) > 3 Then ' source file found
   
             sFilePath = sFolderPath & sFileName
   
             dFilePath = dFolderPath & sFileName
   
             If Not fso.FileExists(dFilePath) Then ' the source file...
   
                 fso.CopyFile sFilePath, dFilePath ' ... doesn't exist...
   
                 sYesCount = sYesCount + 1 ' ... in the destination
   
             Else ' the source file exists in the destination folder
   
                 dYesCount = dYesCount + 1
   
             End If
   
         Else ' the source file doesn't exist
   
             sNoCount = sNoCount + 1
   
         End If
   
         sFileName = Dir
   
     Loop
   
 Else ' the cell is blank
   
     BlanksCount = BlanksCount + 1
   
 End If

Next r

End Sub

Another Code which I run after copying the file to Destination folder which moves the files from Source to Archive folder.

Sub moveAllFilesInDateFolderIfNotExist()

 Dim DateFold As String, fileName As String, objFSO As Object

 Const sFolderPath As String = "E:\Uploading\Source"

 Const dFolderPath As String = "E:\Uploading\Archive"

 DateFold = dFolderPath & "\" & Format(Date, "ddmmyyyy") ' create the folder 
if it does not exist

 If Dir(DateFold, vbDirectory) = "" Then MkDir DateFold

 fileName = Dir(sFolderPath & "\*.*")

 Set objFSO = CreateObject("Scripting.FileSystemObject")

 Do While fileName <> ""

    If Not objFSO.FileExists(DateFold & "\" & fileName) Then

       Name sFolderPath & "\" & fileName As DateFold & "\" & fileName

    Else

        Kill DateFold & "\" & fileName

        Name sFolderPath & "\" & fileName As DateFold & "\" & fileName

    End If

    fileName = Dir

 Loop

End Sub
FaneDuru
  • 38,298
  • 4
  • 19
  • 27
Salman Shafi
  • 249
  • 9
  • Dear @faneDuru can you help in this question – Salman Shafi Nov 28 '22 at 12:17
  • Fane will not be notified as he has not yet replied to this topic. You cannot just tag someone like that on Stack Overflow. – braX Nov 28 '22 at 12:20
  • Okay, so can you help in this regard – Salman Shafi Nov 28 '22 at 12:27
  • *"and i have added another macro which after some times removed the file from Source folder."* - maybe just add that code into this code, once it has performed all the loops? – CLR Nov 28 '22 at 12:35
  • I believe adding file removing code into first code will not resolve the problem, this way all the files which are in the source folder will get removed, how we will identify which file is not copied. – Salman Shafi Nov 28 '22 at 12:45
  • I am not sure that I correctly understood your question... So, the code you show should be the one covered by "I have added another macro"? If so, I cannot understand such a bushy code for something which could be done in a simpler way. If not, please clarify what you wonted to say when wrote the words between double quote. Please, also clarify what "after some times"does mean. Do you want a specific such piece of code to run after some time **after the moving files in specific folders finished its job**? Then, this type of files cannot be identif, only to be moved all in the new folder. – FaneDuru Nov 28 '22 at 13:25
  • Are there **other files which should be excepted from moving**? If so, you should supply a list with their names... – FaneDuru Nov 28 '22 at 13:26
  • Let me add another code which removed the files from source folder, let me update the question – Salman Shafi Nov 28 '22 at 13:31
  • I needed some amendment in the first code "Sub moveFilesFromListPartial()" so that if any file which comes in source folder and whose file name is not matching with what is written in excel sheet it should move to another folder – Salman Shafi Nov 28 '22 at 13:36
  • Definitely files whose names does not match with what is written in excel will not get copy and after 2 minutes another macro "Sub moveAllFilesInDateFolderIfNotExist()" will run which moves all the files from source to Archive. With this process currently i am not able to identify which files have incorrect file names and is not copied to required destination but eventually moved to Archive. – Salman Shafi Nov 28 '22 at 13:37
  • If you do not (correctly) tag me, I CANNOT SEE YOUR COMMENTS trying to address me... I asked some specific questions but you din not answer them: Are there some other files you want them to remain, to not be moved? – FaneDuru Nov 28 '22 at 13:56
  • Dera @FaneDuru I want all the files should be moved from source folder to Archive but in the first code there should be some amendments which will copy the incorrect files in another folder which can be named "Error foler" – Salman Shafi Nov 28 '22 at 13:58
  • Dear @FaneDuru I need to rush out for some important work, i will be online after 3 to 4 hours. Take Care – Salman Shafi Nov 28 '22 at 13:59
  • I already posted an answer. – FaneDuru Nov 28 '22 at 14:01

1 Answers1

0

Please, use the next updated (your macro):

Sub AddMissingItems()
    Dim Dic As Object, arr() As Variant, outArr() As Variant
    Dim i As Long, k As Long, iRow As Long, c As Long
    Dim r As Long, j As Long
    
    Set Dic = CreateObject("Scripting.dictionary")
    With Sheets("Sheet1")
        arr = .Range("A1:A" & .Range("A" & .rows.count).End(xlUp).row).Value
        For i = 1 To UBound(arr, 1)
            If Dic.Exists(arr(i, 1)) = False Then
                Dic.Add (arr(i, 1)), ""
            End If
        Next
    End With
    With Workbooks("ExtractFile.xlsx").Worksheets("Sheet1")
        c = .cells(1, Columns.count).End(xlToLeft).column
        r = .Range("A" & .rows.count).End(xlUp).row 'calculate the last row in A:A, too
        arr = .Range("A1", .cells(r, c)).Value       'place in the array all existing columns
        ReDim outArr(1 To UBound(arr), 1 To c) 'extend the redimmed array to all columns
        
        For i = 1 To UBound(arr)
            If Dic.Exists(arr(i, 1)) = False Then
                k = k + 1
                For j = 1 To c 'iterate between all array columns:
                    outArr(k, j) = arr(i, j) 'place the value from each column
                Next j
            End If
        Next
    End With
    iRow = Sheets("Sheet1").Range("A" & rows.count).End(3).row + 1
    If k <> 0 Then
        Sheets("Sheet1").Range("A" & iRow).Resize(k, UBound(arr, 2)).Value = outArr 'resize by  columns, too
        k = 0
    End If
End Sub
Sub moveFilesFromListPartial()
 Const sPath As String = "E:\Uploading\Source", dPath As String = "E:\Uploading\Destination"
 Const Col As String = "B", colExt As String = "C"
    
    ' Reference the worksheet.
    Dim ws As Worksheet: Set ws = Sheet2

    ' Calculate the last row,
    Dim lRow As Long: lRow = ws.cells(ws.rows.count, Col).End(xlUp).row
                
    ' Validate the last row.
    If lRow < 2 Then MsgBox "No data in column range.", vbCritical: Exit Sub

    Dim fso As Scripting.FileSystemObject
    Set fso = New Scripting.FileSystemObject

    ' Validate the source folder path.
    Dim sFolderPath As String: sFolderPath = sPath
    If Right(sFolderPath, 1) <> "\" Then sFolderPath = sFolderPath & "\"

    If Not fso.FolderExists(sFolderPath) Then
        MsgBox "The source folder path '" & sFolderPath & "' doesn't exist.", vbCritical: Exit Sub
    End If
    
    ' Validate the destination folder path.
    Dim dFolderPath As String: dFolderPath = dPath
    If Right(dFolderPath, 1) <> "\" Then dFolderPath = dFolderPath & "\"

    If Not fso.FolderExists(dFolderPath) Then
        MsgBox "The destination folder path '" & dFolderPath & "' doesn't exist.", vbCritical: Exit Sub
    End If
    
    Dim r As Long, sFilePath As String, sPartialFileName As String, sFileName As String
    Dim dFilePath As String, sExt As String  'extension (dot inclusive)
    
    '_________________________________________________________________________________
    Dim arrC, k As Long 'an array to keep the copied fileNames and a variable to keep
                                           'the next array element to be loaded
    Dim objFolder As Object: Set objFolder = fso.GetFolder(sPath)
    ReDim arrC(objFolder.files.count) 'redim the array at the number of total files
    '_________________________________________________________________________________
    
    For r = 2 To lRow
        sPartialFileName = CStr(ws.cells(r, Col).Value)
        sExt = CStr(ws.cells(r, colExt).Value)
        If Len(sPartialFileName) > 3 Then ' the cell is not blank
           sFileName = Dir(sFolderPath & sPartialFileName & "*" & sExt)
       
          Do While sFileName <> ""
              If Len(sFileName) > 3 Then ' source file found
                  sFilePath = sFolderPath & sFileName
                  dFilePath = dFolderPath & sFileName
                  If Not fso.FileExists(dFilePath) Then ' the destination file...
                      fso.CopyFile sFilePath, dFilePath  ' ... if doesn't exist...
                      
                      '________________________________________________________________________
                      arrC(k) = sFileName: k = k + 1 'each copied file name is loaded in the array
                      '________________________________________________________________________
                      
                  Else
                         '______________________________________________________________________
                      arrC(k) = sFileName: k = k + 1 'each copied file name is loaded in the array
                      '________________________________________________________________________
                  End If
              End If
              sFileName = Dir
          Loop
     End If
   Next r
   
    '__________________________________________________________________________________
    If k > 0 Then ReDim Preserve arrC(k - 1) 'keep in the array only loaded elements
    moveReminedFiles sPath, arrC
   '_________________________________________________________________________________
End Sub

All modifications are between '_______________ lines

Copy the next Sub, which is called by the above one, in the same module:

Sub moveReminedFiles(sFolder As String, arr)
    Dim fileName As String, mtch
    Const destFolder As String = "E:\Uploading\Error Files\" 'use here your folder where errored files to be moved
    If Right(sFolder, 1) <> "\" Then sFolder = sFolder & "\"
    
    fileName = Dir(sFolder & "*.*")
    Do While fileName <> ""
        mtch = Application.match(fileName, arr, 0) 'if the file name does not exist in the array:
        If IsError(mtch) Then Name sFolder & fileName As destFolder & fileName  'move it
        
        fileName = Dir
    Loop
End Sub

Please, test it and send some feedback. Of course, the bushy code could not be tested...

Edited:

Please, try the next updated (former) Sub which comes after the above code, moving all files in the Archive folder. Now, it should also do what you required in this question. Since it is not tested, you should send some feedback after testing it:

Sub moveAllFilesInDateFolderIfNotExist(sFolderPath As String, arr)
 Dim DateFold As String, fileName As String, objFSO As Object, mtch
 Const dFolderPath As String = "E:\Uploading\Archive\"
 Const errFolder As String = "E:\Uploading\Error Files\"
 
 If Right(sFolderPath, 1) <> "\" Then sFolderPath = sFolderPath & "\"
 DateFold = dFolderPath & "\" & Format(Date, "ddmmyyyy") & "\" ' create the cur date folder name

 If Dir(DateFold, vbDirectory) = "" Then MkDir DateFold 'create the necessary folder if it does not exist
 
 fileName = Dir(sFolderPath & "\*.*")
 Set objFSO = CreateObject("Scripting.FileSystemObject")
 
 Do While fileName <> ""
    mtch = Application.match(fileName, arr, 0)
    If IsError(mtch) Then  'if the file name does not exist in the array:
        If objFSO.FileExists(errFolder & "\" & fileName) Then
           Kill errFolder & fileName
        End If
        Name sFolderPath & fileName As errFolder & fileName  'move it
    Else
        If Not objFSO.FileExists(DateFold & "\" & fileName) Then
            Name sFolderPath & fileName As DateFold & fileName
        Else
            Kill DateFold & fileName
            Name sFolderPath & fileName As DateFold & fileName
        End If
    End If
    fileName = Dir
 Loop
End Sub

You only have to change moveReminedFiles sPath, arrC with moveAllFilesInDateFolderIfNotExist sPath, arrC and run it. Take care that now it will also move the files in the archive folder. Of course, except the wrong spelled ones which will be moved in their special Error folder...

Please, send some feedback after testing it.

FaneDuru
  • 38,298
  • 4
  • 19
  • 27
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/250000/discussion-on-answer-by-faneduru-files-whose-source-is-not-in-excel-sheet-should). – sideshowbarker Nov 29 '22 at 22:24
  • Dear @FaneDuru the solution you have provided is unbelievable, it is working exactly as per the requirement. I would like to thank you especially for your intense patience, concepts, hardworking and taking interest in providing solution to a new learner like me. Thank you so much – Salman Shafi Nov 30 '22 at 06:02
  • Dear @faneDuru just one thing left in Sub moveAllFilesInDateFolderIfNotExist(sFolderPath that if the file is already available in archive folder and that it the same file been uploaded than it first kills the previous file from Archive and move the updated one, (however all other functions remain intact) – Salman Shafi Nov 30 '22 at 06:40
  • @Salman Shafi Yes, I missed that part. I looked to the code I have, but I did the modification on your computer and it was missing it, I forgot about it... I will do the modification now, but wouldn't it be better to proceed in a similar way with moving files in the "Error Folder"? For the case you missed emptying it. Or, if you do not need the previous files, to make the code firstly deleting all existing files from "Error Folder" and not caring about the issue in the rest of the code... How do you like it being, according to your real needs scenario? Adapted the code, for Archive folder case – FaneDuru Nov 30 '22 at 10:24
  • Dear @FaneDuru The rest of the code is working perfectly wonderful and fulfilling all the needs, In real scenario it happens that users do move the files twice same day (correct files) in Source folder and therefore if we do not replace the correct file in Archive it will keep stuck in Source folder, you know, therefore can you please use the kill command as you have used previously and kindly amend the code moveAllFilesInDateFolderIfNotExist(sFolderPath – Salman Shafi Nov 30 '22 at 10:39
  • @Salman Shafi I am afraid I cannot get you... Did you refresh the page (this one)? I already adapted the code to firstly delete/kill the file from Archive, if it exists there. I asked if it is better for you to proceed in a similar way with Error folder... – FaneDuru Nov 30 '22 at 10:45
  • Ok Sorry, i didnot check, let me check, thanks – Salman Shafi Nov 30 '22 at 10:49
  • Dear @FaneDuru whenever you have time, can you please also review my new query at https://stackoverflow.com/questions/74624324/to-make-automatic-folders-extension-wise?noredirect=1#comment131722691_74624324 Do you remember you have provided one more wonderful solution which you can see, https://stackoverflow.com/questions/74568885/to-copy-files-with-similar-name-into-folders?noredirect=1#comment131636931_74568885 – Salman Shafi Nov 30 '22 at 11:02
  • @Salman Shafi Now I need to go out for some time. If somebody else will not answer your question, I will try doing it. At the first glance, if you have that error you should simple declare the respective variable `Dim NewFoldpath As String`... – FaneDuru Nov 30 '22 at 11:09
  • @Salman Shafi I think you should read what I wrote to the respective question and after understanding it delete the question. If something from my comment not clear enough, please ask (here) for clarifications. And I remember you that I asked two times about the idea of also overwriting the **existing files in the Error folder**. With the option of preliminary killing all files from the respective folder... – FaneDuru Nov 30 '22 at 13:55
  • Dear @FaneDuru everything is perfectly running fine, no issues, all good – Salman Shafi Nov 30 '22 at 14:08
  • @Salman Shafi I was firstly referring to the other question we were talking about after showing its link... Then, the code of the above answer works, I know that. But **I was asking myself what will happen if you do not delete a file from Error Folder, which will be found AGAIN running the code**. Now, it will raise an error on line `Name sFolderPath & fileName As errFolder & fileName`... Please, carefully read some of my above comments related to this issue! – FaneDuru Nov 30 '22 at 14:13
  • let me check them multiple times and i will revert – Salman Shafi Dec 01 '22 at 07:49
  • Dear @FaneDuru it gives "Subscription out of range" error Runtime error 9 – Salman Shafi Dec 01 '22 at 09:48
  • @Salman Shafi Only saying something about an error, is not of any help... **On which code line is the respective error raised**? – FaneDuru Dec 01 '22 at 12:24
  • Dear @FaneDuru Today was a day i could not work much on code after 1 hour and just came in my cabin now. I am going out of city for next 3 days and will have limited access of internet, i will come and will check this in detail, and will update you. Thank you and take care – Salman Shafi Dec 01 '22 at 13:34
  • @Salman Shafi OK. I cannot help in any way in these circumstances. I will try helping when having more pieces of information. Or connecting to your computer to see what's happening there... Nave a nice trip! – FaneDuru Dec 01 '22 at 13:44
  • Dear @FaneDuru i just came back, i will check in detail today and will revert. Thanks, it was a wonderful trip. hope you doing great too. – Salman Shafi Dec 05 '22 at 05:31
  • Dear @FaneDuru I have checked the process in very detail, while moving files it works wonderful, however after some time it gives error "Subscript out of range" at line '______________________________________________________________________ arrC(k) = sFileName: k = k + 1 'each copied file name is loaded in the array – Salman Shafi Dec 06 '22 at 07:25
  • currently i am working on your previously provided sub Sub moveReminedFiles(sFolder As String, arr) – Salman Shafi Dec 06 '22 at 07:26
  • @Salman Shafi May I connect to your computer? Theoretically, "Subscript out of range" error should be raised only if the code tries loading `arrC` with a `k` bigger than the dimensioned array. Please, insert `Debug.Print "Ubound arrC = " & Ubound(arrC)` immediately after `ReDim arrC(objFolder.files.count)` code line. When code is stopped on the respective error, what value does `k` have and what did the `Debug.Prind` send to `Immediate Window`? Is it `k` greater then `Ubound(arrC)`? – FaneDuru Dec 06 '22 at 08:33
  • my Dear @FaneDuru I am afraid currently it is not possible via anydesk, i will check your advise in detail and will revert. – Salman Shafi Dec 06 '22 at 08:53
  • Dear @FaneDuru I am working on your previously defined code daily, actually there are 23 sub added after your codes that is why your previous code is currently working perfectly. However, i am facing just one issue however so far found a solution for that and working on it. hope you are doing great – Salman Shafi Dec 08 '22 at 12:15
  • @Salman Shafi I'm afraid that I cannot understand too much from what you are saying... Neither related to the "previously defined code", neither related to the "23 added subs". But, if you are satisfied with what you are doing, I do not have any problem...:) I am doing well, thanks for asking! – FaneDuru Dec 08 '22 at 12:52
  • 1
    LOL. I mean there are several processes connected with your suggested macros and everything is based on what you have provided, however, up till now everything is running up to the mark, if i stuck anywhere definitely i will ask for the help. Have a nice time – Salman Shafi Dec 08 '22 at 13:21
  • Dear @FaneDuru I have put the line Debug.Print "Ubound arrC = " & Ubound(arrC) immediately after teh line Redim Arrac(objfolder.files.count) now i am observing the result in immediate windows, currently it says that e.g. Ubound arrC = 50, then Ubound arrC = 0 Ubound arrC = 25 – Salman Shafi Dec 09 '22 at 07:11
  • i will monitor at times when error comes what it shows in immediate windows and i will tell you – Salman Shafi Dec 09 '22 at 07:12
  • Dear @FaneDuru it gives error at line arrC(k) = sFileName: k = k + 1 'each copied file name is loaded in the array (the error is subscript out of range) – Salman Shafi Dec 09 '22 at 07:25
  • the immediate windows gives this msg Ubound arrC = 0 Ubound arrC = 0 Ubound arrC = 4 Ubound arrC = 16 – Salman Shafi Dec 09 '22 at 07:25
  • When `Ubound(arrC) = 0` this means that the folder in discussion DOES NOT HAVE ANY FILE. What does `sFileName` and `k` values shows moving the cursor over them when stopped on error? The above values regarding array number of elements are shown ONLY FOR THE CASES OF ERRORING? Are there cases when error is raising when `Ubound(arrC)` is not zero? – FaneDuru Dec 09 '22 at 09:18
  • Dear @FaneDuru I hope everything is fine at your end. long time, no talk.... Sir I just need a little edit in a sub Sub moveReminedFiles(sFolder As String, arr) – Salman Shafi Dec 18 '22 at 09:31
  • currently all the solutions you have provided are working perfectly. Just a query is if a file moved into error Folder and it again has uploaded again, the code shows error that "File Already Exist" however is it possible if you could edit the code and add kill command or something so that the process should not be break or shows error – Salman Shafi Dec 18 '22 at 09:32
  • it could kills the previous file and re-uploaded the latest file in "Error Folder" – Salman Shafi Dec 18 '22 at 09:33
  • @Salman Shafi I am afraid that what you say cannot be possible... The code in discussion previously check if the file to be moved already exists and then move it if not, or kills it and only after that it moves it... – FaneDuru Dec 18 '22 at 10:46
  • Reading your third comment, I must confess that I cannot get you, anymore... What does **it could kills the previous file and re-uploaded the latest file in "Error Folder"** mean? Does it kill a previous existing file or not, as you said in your previous comment? If I remember well, `moveReminedFiles` should not be used, anymore. the updated last function should do it. Am I missing anything? I checked and I could see that I wrote: **You only have to change `moveReminedFiles sPath, arrC` with `moveAllFilesInDateFolderIfNotExist sPath, arrC` and run.** – FaneDuru Dec 18 '22 at 10:47
  • Dear @FaneDuru You have understood the point correctly that, it happens sometimes where we have thousands of files everyday, where a team member mistakenly have added a incorrect file name and paste it in source folder (which will move into Error folder), there is 5% probability that they could add the same file with incorrect spelling again. currently this is stopping the process and it displays msg that "File Already exists" – Salman Shafi Dec 18 '22 at 11:32
  • I wish if there is any solution for this hopefully last query – Salman Shafi Dec 18 '22 at 11:32
  • secondly I am using Sub moveReminedFiles(sFolder As String, arr) this is working perfectly 100% with no issues. i am okay with this sub . Thanks :) – Salman Shafi Dec 18 '22 at 11:33
  • @Salman Shafi If you use `moveReminedFiles` **I cannot help you in any way**. If you use the updated `moveAllFilesInDateFolderIfNotExist` (but after refreshing this page), **completely renouncing to `moveReminedFiles`, as suggested, you probably will not face any issue**... – FaneDuru Dec 18 '22 at 12:00
  • Okay let me try the new updated sub which is moveAllFilesInDateFolderIfNotExist , thank you so much – Salman Shafi Dec 18 '22 at 12:28
  • Dear @FaneDuru yes it is working perfectly. but i will check it multiple times for 3 to 4 days to see if there is any issue or not. (you are genius by the way) :) – Salman Shafi Dec 18 '22 at 13:08
  • @Salman Shafi It shouldn't have any problem, I think. It initially was not designed for such a case. You did not required such an option and I did not imagine that somebody can make the same naming mistake... And I am not a genius! I only try finding solutions, **if I correctly understand what is to be done and all involved circumstances**... – FaneDuru Dec 18 '22 at 14:46
  • @FaneDuru Yes you have understood and you have provided the wonderful solution. currently those macros are working 24 hours. and i am testing and checking them daily – Salman Shafi Dec 19 '22 at 07:32
  • i must say Thank you so much – Salman Shafi Dec 19 '22 at 07:32