This example explains Macro or VBA code to create list of all files from a selected folder. Select Folder then VBA Code will capture path in a cell and create list of all all files existing in that folder on excel sheet.
Thank you so much How do I add file names in a column and an extension in a column ... When I click and choose a folder, it clears all the previous information
The code may work fine, but what you call 'formatting' is ridiculous and bad programming style. You should NOT remove blank lines between diffferent parts of the program and you should definitely use indentation to make the code more readable ! At least you use some comments ...