+ Reply to Thread
Results 1 to 5 of 5

Deleting several files within one folder

  1. #1
    Registered User
    Join Date
    01-15-2011
    Location
    Clearfield, UT
    MS-Off Ver
    Excel 2016
    Posts
    58

    Deleting several files within one folder

    I'm trying to create a macro that will delete several files within the same folder. I use the following to delete the file 1_OSHA LOG_2012 .xls:

    Please Login or Register  to view this content.
    However, I need a macro that will allow me to delete many files within the same folder, for example:

    1_OSHA LOG_2012 .xls
    10_OSHA LOG_2012 .xls
    11_OSHA LOG_2012 .xls
    12_OSHA LOG_2012 .xls
    13_OSHA LOG_2012 .xls
    38_OSHA LOG_2012 .xls
    110_OSHA LOG_2012 .xls
    815_OSHA LOG_2012 .xls

    Is this possible? If so, I would appreciate any help you can provide to me. JPDutch
    Last edited by JPDutch; 11-28-2012 at 12:33 AM. Reason: Solved

  2. #2
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Deleting several files within one folder

    Hi
    enter your file names in a range in the worksheet (I've specified A1:A8 in this example) and try this macro:

    Please Login or Register  to view this content.
    Last edited by NickyC; 11-27-2012 at 09:25 PM. Reason: correct code

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Deleting several files within one folder

    If that code works then maybe this?

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  4. #4
    Registered User
    Join Date
    01-15-2011
    Location
    Clearfield, UT
    MS-Off Ver
    Excel 2016
    Posts
    58

    Re: Deleting several files within one folder

    The "file names in a range" macro did it! Thank you very much NickyC.

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Deleting several files within one folder

    A little trick to make the "range" dynamic. Assuming all the strings are typed into those cells in column A and not formulaic, this will grab all those cells, however many there are, ignoring blank cells:

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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