+ Reply to Thread
Results 1 to 10 of 10

To retrieve a single cell's value for all Excel files in a folder

Hybrid View

alice2011 To retrieve a single cell's... 04-24-2015, 05:06 AM
Crooza Re: To retrieve a single... 04-24-2015, 05:38 AM
alice2011 Re: To retrieve a single... 04-24-2015, 06:53 AM
jindon Re: To retrieve a single... 04-24-2015, 05:39 AM
alice2011 Re: To retrieve a single... 04-24-2015, 06:55 AM
Crooza Re: To retrieve a single... 04-24-2015, 07:04 AM
alice2011 Re: To retrieve a single... 04-24-2015, 10:19 AM
jindon Re: To retrieve a single... 04-24-2015, 07:07 AM
alice2011 Re: To retrieve a single... 04-24-2015, 10:18 AM
Crooza Re: To retrieve a single... 04-24-2015, 06:59 AM
  1. #1
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: To retrieve a single cell's value for all Excel files in a folder

    Try this just change the directory to the correct path (in red below)

    Sub LoopThroughFolder()
    
        Dim MyFile, myval As String, Str As String, MyDir As String, Wb As Workbook
        Dim Rws As Long, Rng As Range
        Dim i As Integer
        
        Set Wb = ThisWorkbook
        'change the address to suite
        MyDir = "C:\temp\customer\"
        MyFile = Dir(MyDir & "*.xlsx")    'change file extension
        ChDir MyDir
        Application.ScreenUpdating = 0
        Application.DisplayAlerts = 0
    
        Do While MyFile <> ""
            Workbooks.Open (MyFile)
            With Worksheets(1)
                
                myval = Range("I41").Value
                
                Wb.Sheets(1).Cells(Rows.Count, "B").End(xlUp).Offset(1, 0) = myval
                Wb.Sheets(1).Cells(Rows.Count, "A").End(xlUp).Offset(1, 0) = MyFile
    
                ActiveWorkbook.Close True
            End With
            MyFile = Dir()
        Loop
    
    End Sub
    Happy with my advice? Click on the * reputation button below

  2. #2
    Forum Contributor
    Join Date
    01-16-2014
    Location
    London
    MS-Off Ver
    Excel 2003 Excel 2010
    Posts
    189

    Re: To retrieve a single cell's value for all Excel files in a folder

    Hi Crooza, thanks for your help

    I tried your code and it seemed that there is some problem:

    1) There is a message popping up all the time: "This workbok contains links to other data sources". So I need to constantly click the 'Update' button.

    2) After that, the macro stopped with an error message: "Run-time error '13': Type mismatch".

    I added the statement On Error Resume Next. But the macro ran for a while and terminated unexpectedly and the file closed.

    Can you please have a look? Thanks

+ 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. Copy same ranges in all excel files in a folder into a single workbook
    By ple in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-18-2013, 10:03 AM
  2. excel macro to copy data from multi text files in a folder to a single work sheet
    By dil_se in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-16-2012, 08:10 AM
  3. Replies: 1
    Last Post: 09-18-2012, 05:26 AM
  4. Merging particular worksheet from Multiple Files in a folder into a single workbook
    By excelhelp18 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-30-2012, 01:37 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