title: Excel VBA to get a file list by multiple file extensions and last modified date
body: <p>In my folder, I have different types of files:<br><br>
  <strong>.mp4 .wav .out .outreview</strong>
  <br><br>
  I am using a VBA code in excel to make a list of all of the files according to their file extension. As seen in the screenshot:
  <br><br>
  <img src="https://i.stack.imgur.com/symWe.png" alt="enter image description here"></p>
  
  <p><br><br>
  To do this, I use the following code four times, each time I replace the file extension and adjust the column references:
  <br><br>this is the example code for the first column, the video files, .mp4:<br><br></p>
  
  <pre><code>Sub getfilelistfromfolder()
      Dim varDirectory As Variant
      Dim flag As Boolean
      Dim i As Long
      Dim strDirectory As String
      Dim Desired As String
  
      strDirectory = Application.ActiveWorkbook.Path &amp; "\"
      i = 1
      flag = True
      varDirectory = Dir("C:\Users\Folder\*.mp4", vbNormal)
      Range("A5:A100").Select
      Selection.ClearContents
  
      While flag = True
          If varDirectory = "" Then
              flag = False
          Else
              Cells(i + 4, 1) = varDirectory
              varDirectory = Dir
              i = i + 1
          End If
      Wend
  End Sub
  </code></pre>
  
  <p><br><br>
  I repeat it for .wav and .outreview files.
  But I use the following code for .out files, because, otherwise, it pulls up all the .out and . outreview files in the .out column, which I don't want.<br><br></p>
  
  <pre><code>Sub getfilelistfromfolder()
      Dim varDirectory As Variant
      Dim flag As Boolean
      Dim i As Long
      Dim strDirectory As String
      Dim Desired As String
  
  Desired = ".out"
  
  strDirectory = Application.ActiveWorkbook.Path &amp; "\"
  i = 1
  flag = True
  varDirectory = Dir("C:\Users\Folder\", vbNormal)
  
  While flag = True
      If varDirectory = "" Then
          flag = False
      Else
          If Right(varDirectory, 4) = Desired Then
              Cells(i + 4, 3) = varDirectory
              i = i + 1
          End If
          varDirectory = Dir
      End If
  Wend
  End Sub
  </code></pre>
  
  <p><br><br>
  <strong>Question:</strong> how can I pull the last modified date <strong>ONLY</strong> for .out files and put them in their corresponding cells in column <strong>D</strong>?
  <br><br>And how can I combine all these codes into one code so that I don't repeat this for each file extension?
  Thanks
  <br><br><br><br>
  <strong><em>UPDATE</em></strong>:
  <br><br><br><br>
  this update is after the answer provided by <em>Jeanno</em>:
  <br><br>
  This answers my question. here is the Jeanno's corrected version of the code.</p>
  
  <p><br><br></p>
  
  <pre><code>Sub getfilelistfromfolder()
      Dim varDirectory As Variant
      Dim flag As Boolean
      Dim i As Long
      Dim strDirectory As String
      Dim Desired As String
  
      strDirectory = Application.ActiveWorkbook.Path &amp; "\"
      i = 1
      flag = True
      varDirectory = Dir("C:\Users\folder\*", vbNormal)
      Range("A5:E100").clear
  
  While flag = True
          If varDirectory = "" Then
              flag = False
          Else
          If varDirectory Like "*.mp4" Then
              Cells(i + 4, 1) = varDirectory
          End If
          If varDirectory Like "*.wav" Then
              Cells(i + 4, 2) = varDirectory
              i = i + 1
          End If
          If varDirectory Like "*.outreview" Then
              Cells(i + 4, 5) = varDirectory
          End If
          If varDirectory Like "*.out" Then
              Cells(i + 4, 4) = varDirectory
              Cells(i + 4, 3) = FileDateTime("C:\Users\folder\" &amp; varDirectory)
          End If
          varDirectory = Dir
          End If
  Wend
  End Sub
  </code></pre>
  
  <p><br><br></p>