+ Reply to Thread
Results 1 to 6 of 6

Count files in a folder

  1. #1
    Registered User
    Join Date
    10-11-2021
    Location
    Luxembourg
    MS-Off Ver
    2109
    Posts
    4

    Lightbulb Count files in a folder

    Hey folks,

    I am not an expert in VBA, but according to my research, the function I intend to perform will not be possible to do with excel formulas. In this case I will have to dedicate myself to programming in VBA Macros.

    I'm looking for a function that tells me the number of files in a specific folder, and put the result in a specific cell on the worksheet.

    The exemple :

    I want to know how many files i have in this folder :

    C:\Users\Veiga\Desktop\Final\PR0015\

    And i want the result ( number of files ) in a specific Cell ( D9 ) exemple .

    That is the main task for second and better task i want to upgrade the code, the folder PR0015 have more similar folders like : PR0015; PR0016; PR0017; PR0018 ......


    So i want to put the folder name in the Cell ( A1 ) exmple
    Then i want to know how many files i have in this folder :

    C:\Users\Veiga\Desktop\Final\ (A1) \

    Like this is a dynamic worksheet where can i change the address

    In last task it will be possible to make in the same cell (D9) a droplist with the name of all the files names inside the folder .

    Thank you for your help,

    Best regards ,

    Veiga

  2. #2
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Count files in a folder

    http://www.vbaexpress.com/kb/getarticle.php?kb_id=238

    works for me and gives the total number of files

    Please Login or Register  to view this content.
    Will give you a list of all the files in the folder in range A1, alter accordingly. This range would have to be set as the source for the dropdown you are wanting in the cell

  3. #3
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,032

    Re: Count files in a folder

    Might also be able to work it into a UDF

    So, if your path was in A1, you could put the formula =Splitfiles(A1) which would give you the number and the list of files, at least in O365.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    10-11-2021
    Location
    Luxembourg
    MS-Off Ver
    2109
    Posts
    4

    Re: Count files in a folder

    Hello Good Morning .

    Thank you very much for your help . I used the code of --davsth-- , it was very very good .

    --- davsth in your code we can add 2 more rules:

    - Count the number of files and Subfolders inside a folder ( ex: Result = 8 -- 5 files and 3 subfolders )
    - And if the the file doesn't exist - the result show me the text ( NOT FIND )

    Again, thank you very much for your help.

    Veiga

  5. #5
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Count files in a folder

    Does a file exist

    https://www.automateexcel.com/vba/file-exists/

    for the other question I would probably just count the files listed, if the folders are names without . countif(list of files and folders,"*.*") would give the number

  6. #6
    Registered User
    Join Date
    10-11-2021
    Location
    Luxembourg
    MS-Off Ver
    2109
    Posts
    4

    Re: Count files in a folder

    Davsth, thanks ,

    Just a small help again :

    In the code :

    Sub CheckFolderExists ()

    Dim strFolderName As String
    Dim strFolderExists As String

    strFolderName = "C:\Users\Nikola\Desktop\VBA articles\Test Folder\"
    strFolderExists = Dir(strFolderName, vbDirectory)

    If strFolderExists = "" Then
    MsgBox "The selected folder doesn't exist"
    Else
    MsgBox "The selected folder exists"
    End If

    End Sub

    When i have this line -Else
    MsgBox "The selected folder exists"

    can i put the routine " ELSE - Counting files and folders inside that extention ? "....

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Count .xls files and .txt files in a folder
    By KColgrove in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-01-2019, 04:26 PM
  2. [SOLVED] VBA Count the Files in a Folder
    By KColgrove in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-31-2019, 09:08 AM
  3. [SOLVED] Dynamically count the number of files in a folder
    By 63falcondude in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-14-2019, 02:54 PM
  4. Replies: 2
    Last Post: 06-01-2012, 07:40 AM
  5. count files in a folder automatically??
    By benjii19 in forum Excel General
    Replies: 13
    Last Post: 03-01-2011, 11:32 AM
  6. count the number of files in a specified folder
    By bambino86 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-04-2009, 12:55 PM
  7. [SOLVED] Count files in folder
    By gmunro in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-18-2005, 06:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1