# List the files in the folder



## mmn1000 (Jan 4, 2023)

*Hi,
I list the files in the data folder using the code below*

```
Sub listoffile()
Dim directory As String, fileName As String, sheet As Worksheet, i As Integer
directory = "D:\Data\"
fileName = Dir(directory & "*.*")
Do While fileName <> ""
    i = i + 1
    Cells(i, 6) = fileName
    fileName = Dir()
Loop
End Sub
```

*In this code, the list of my files starts from cell F1, for example
I want it to start listing from cell F8 instead of F1*
    i = i + 1
    Cells(i, 6) = fileName


----------



## jolivanes (Jan 4, 2023)

```
Sub listoffile()
Dim directory As String, fileName As String, sheet As Worksheet, i As Integer
directory = "D:\Data\"
fileName = Dir(directory & "*.*")
i = 7    '<---- Insert this line here
Do While fileName <> ""
Rest of code
```


----------



## jolivanes (Jan 4, 2023)

```
Sub This_Might_Be_Faster()
    Dim filelist() As String, i As Long, fName As String
    fName = Dir("D:\Data" & "\*.*")
    While fName <> ""
        i = i + 1
        ReDim Preserve filelist(1 To i)
        filelist(i) = fName
        fName = Dir()
    Wend
    Cells(8, 6).Resize(UBound(filelist)) = Application.Transpose(filelist)
End Sub
```


----------



## mohadin (Jan 4, 2023)

```
Sub listoffile()
Dim directory As String, fileName As String, sheet As Worksheet, i As Integer
directory = "D:\Data\"
fileName = Dir(directory & "*.*")
i=7
Do While fileName <> ""
    i = i + 1
    Cells(i, 2) = fileName
    fileName = Dir()
Loop
End Sub
```


----------



## mmn1000 (Jan 4, 2023)

jolivanes said:


> ```
> Sub This_Might_Be_Faster()
> Dim filelist() As String, i As Long, fName As String
> fName = Dir("D:\Data" & "\*.*")
> ...


Thank you for your beautiful guide, it was great


----------



## mmn1000 (Jan 4, 2023)

mohadin said:


> ```
> Sub listoffile()
> Dim directory As String, fileName As String, sheet As Worksheet, i As Integer
> directory = "D:\Data\"
> ...


Thank you


----------



## jolivanes (Jan 5, 2023)

@mmn1000 
Thank you for the updates and good luck


----------

