+ Reply to Thread
Results 1 to 18 of 18

feth data from cells from all the files in a folder

  1. #1
    Registered User
    Join Date
    10-17-2014
    Location
    Australia
    MS-Off Ver
    2007
    Posts
    29

    feth data from cells from all the files in a folder

    Hey guys

    I have seen a various VBA codes which do a part of what I am trying to achieve, but I couldn't find anything that helps me to do exactly what I want.

    I have got a folder with around 500 excel files (all with a same template) (apart from excel files there are some other subfolders too in this folder). The address of that folder on my computer is \\STM-FS2\shared documents\shared documents\JOB COSTINGS. Now I want to fetch data from cells C4 and O17 from a worksheet named Hours from each file in that folder.

    Please help me with a code that do this.

    Thanks

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: feth data from cells from all the files in a folder

    Hello Mehul Jaganiya,

    Where will the output of the cells go?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    10-17-2014
    Location
    Australia
    MS-Off Ver
    2007
    Posts
    29

    Re: feth data from cells from all the files in a folder

    I have another excel file named Jobs on hand 27.10.14. In this file there is a worksheet named AllHours. The output can be populated in column A and B of this worksheet.

    Thanks

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: feth data from cells from all the files in a folder

    Hello Mehul Jaganiya,

    Thanks for follow up information.

    Are there any restrictions regarding the use of VBA macros on your network?

  5. #5
    Registered User
    Join Date
    10-17-2014
    Location
    Australia
    MS-Off Ver
    2007
    Posts
    29

    Re: feth data from cells from all the files in a folder

    I am not too sure about that, but I do use a lot of other VBA macros and have never had any problems.
    Last edited by Mehul Jaganiya; 10-30-2014 at 06:51 PM.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: feth data from cells from all the files in a folder

    Hello Mehul Jaganiya,

    Okay, I will put some code together and we'll see what happens.

  7. #7
    Registered User
    Join Date
    10-17-2014
    Location
    Australia
    MS-Off Ver
    2007
    Posts
    29

    Re: feth data from cells from all the files in a folder

    Thanks Leith

  8. #8
    Forum Contributor Cerbera's Avatar
    Join Date
    07-06-2010
    Location
    Rotorua, New Zealand
    MS-Off Ver
    Excel 2007, 2013, 2016 & 365
    Posts
    137

    Re: feth data from cells from all the files in a folder

    Hi how about this code:

    Please Login or Register  to view this content.
    I have it running from a workbook called RESULTS.xlsx - you'd want to change that in your code to match your controlling / results work book. Also update the range to be copied over and the name of the directory.

    Leith may be able to improve on this as he's simply put "better" at it than me!
    If I've helped please click on *Add Reputation

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: feth data from cells from all the files in a folder

    Hello Cerbera,

    The only thing I was planning to differently, for the sake of speed, was to access the data with the workbooks closed.

    If speed isn't issue then your code will work fine.

  10. #10
    Registered User
    Join Date
    10-17-2014
    Location
    Australia
    MS-Off Ver
    2007
    Posts
    29

    Re: feth data from cells from all the files in a folder

    Thanks for your help, Cerbera.
    I noticed that the code uses a range of A1:B3. However, I don't want to copy a range. I want to copy only two cells which are C4 and O17. Can I still do it with this code?

  11. #11
    Registered User
    Join Date
    10-17-2014
    Location
    Australia
    MS-Off Ver
    2007
    Posts
    29

    Re: feth data from cells from all the files in a folder

    Also when I ran this code it opened each file in the folder and asked me if I want to save any changes in each file. Is there a way of doing this without opening each files?

  12. #12
    Forum Contributor Cerbera's Avatar
    Join Date
    07-06-2010
    Location
    Rotorua, New Zealand
    MS-Off Ver
    Excel 2007, 2013, 2016 & 365
    Posts
    137

    Re: feth data from cells from all the files in a folder

    Hi Mehul,

    I've tweeked the code for the two different cell references:

    Please Login or Register  to view this content.
    The code could be improved upon, e.g. storing the "current workbook" name rather than hard coding it.

    I'm sure Leith can create something more elegant and efficient, but I fancied giving it a crack, even if it isn't the greatest

  13. #13
    Registered User
    Join Date
    10-17-2014
    Location
    Australia
    MS-Off Ver
    2007
    Posts
    29

    Re: feth data from cells from all the files in a folder

    Thanks Cerbera for addressing the range issue. Can you please also make it able to not open each file in the folder?

  14. #14
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: feth data from cells from all the files in a folder

    Hello

    You can easily prevent the dialog from appearing when closing the workbook by setting the argument SaveChanges to Flase, like this...
    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    10-17-2014
    Location
    Australia
    MS-Off Ver
    2007
    Posts
    29

    Re: feth data from cells from all the files in a folder

    Thanks. That solved the problem. Now the save dialog box is not opening anymore.

    After running the macro excel processed it for about 30 secs but no data was copied from the files. It is all blank.

  16. #16
    Forum Contributor Cerbera's Avatar
    Join Date
    07-06-2010
    Location
    Rotorua, New Zealand
    MS-Off Ver
    Excel 2007, 2013, 2016 & 365
    Posts
    137

    Re: feth data from cells from all the files in a folder

    Hi Mehul,

    Put some breaks in the code and monitor the values and position to see what is happening at each point. You should be able to check which workbooks are opening and whether it is selecting the correct data, etc.

    Also you can add message boxes to show values as the code is processed, e.g.

    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    10-17-2014
    Location
    Australia
    MS-Off Ver
    2007
    Posts
    29

    Re: feth data from cells from all the files in a folder

    Hi Cerbera,

    I am very new to the whole macros area and I am not too sure how to put breaks in the code.

    One thing I noticed is that while the marco is running and going through all the files the active cell doesn't automatically move down the row. My understanding was that we have some sort of counter that makes the active cell to move down every time it loops.

    Please correct me if I am wrong.

  18. #18
    Registered User
    Join Date
    10-17-2014
    Location
    Australia
    MS-Off Ver
    2007
    Posts
    29

    Re: feth data from cells from all the files in a folder

    I found a code which does almost what I am after. The only problem here is that it can not access the file names with symbols like "Simon's Boilers", "Baker's extra", "Sauer's bakehouse" etc.
    Is there a way to fix this thing? Other than that it is all good.

    Please Login or Register  to view this content.

+ 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. Replies: 1
    Last Post: 01-28-2019, 06:55 PM
  2. copying data from excel files in a source folder to target folder
    By Javed07 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-22-2013, 04:27 PM
  3. Need Help Downloading Files into a Folder from Excel cells
    By customframed in forum Excel General
    Replies: 1
    Last Post: 02-28-2012, 04:45 PM
  4. Replies: 1
    Last Post: 06-23-2006, 04:25 PM
  5. Linking cells to files in a folder
    By beginnerExceluser in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 10-04-2005, 02:05 AM

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