The following vba code works perfectly. However I would like it to first clear the…
- User
The following vba code works perfectly. However I would like it to first clear the contents of column A5 to A100 before it pastes into the column. Can you add to the code so that it does this. Sub FileList() Dim xFSO As Object Dim xFolder As Object Dim xFile As Object Dim xFiDialog As FileDialog Dim xPath As String Dim i As Integer Set xFiDialog = Application.FileDialog(msoFileDialogFolderPicker) If xFiDialog.Show = -1 Then xPath = xFiDialog.SelectedItems(1) End If Set xFiDialog = Nothing If xPath = "" Then Exit Sub Set xFSO = CreateObject("Scripting.FileSystemObject") Set xFolder = xFSO.GetFolder(xPath) i = 5 ' Modified line to start the list from A4 without row spaces between the links. For Each xFile In xFolder.files ActiveSheet.Hyperlinks.Add Cells(i, 1), xFile.Path, , , xFile.Name i = i + 1 ' Increment I by 1 for each file. Next End Sub
- Assistant
Sub FileList() Dim xFSO As Object Dim xFolder As Object Dim xFile As Object Dim xFiDialog As FileDialog Dim xPath As String Dim i As Integer
code'Clear contents of column A5 to A100 Range("A5:A100").ClearContents Set xFiDialog = Application.FileDialog(msoFileDialogFolderPicker) If xFiDialog.Show = -1 Then xPath = xFiDialog.SelectedItems(1) End If Set xFiDialog = Nothing If xPath = "" Then Exit Sub Set xFSO = CreateObject("Scripting.FileSystemObject") Set xFolder = xFSO.GetFolder(xPath) i = 5 ' Modified line to start the list from A4 without row spaces between the links. For Each xFile In xFolder.files ActiveSheet.Hyperlinks.Add Cells(i, 1), xFile.Path, , , xFile.Name i = i + 1 ' Increment I by 1 for each file. NextEnd Sub