+ Reply to Thread
Results 1 to 4 of 4

How to Check the Value of a Specific Cell in Every File in Directory

Hybrid View

  1. #1
    Registered User
    Join Date
    07-12-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    67

    How to Check the Value of a Specific Cell in Every File in Directory

    Hi,

    There are approximately 120,000 files in the directory, and only about 8,000 are excel files
    is there a way to list the value of cell 'AA63' (Specifically Sheets("FORM").Range("AA63")) from every workbook in the directory?

    If the process involves opening each one, we can't afford that time, so if it can't be done, we can use an estimate.

    Thanks,
    -Drew

  2. #2
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: How to Check the Value of a Specific Cell in Every File in Directory

    I think it can be done - what kind of files are they? csv/xls/xlsx/xlsm/xlb ?

    But even opening each one via vba should only take a couple of minutes.

  3. #3
    Registered User
    Join Date
    07-12-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    67

    Re: How to Check the Value of a Specific Cell in Every File in Directory

    They're .xlsb
    Thanks!

  4. #4
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: How to Check the Value of a Specific Cell in Every File in Directory

    Use this in the worksheet area of your code:

    Sub excelforum()
    Dim ConT As Object, DataT As Object, constr$, sqlstr$, folder$, getdir
    
    folder = InputBox("Please input the folder location you want to pull the data from." & vbNewLine & vbNewLine & "Syntax: C:\foldername\foldername", "Inputfoldername")
    If Right(folder, 1) <> "\" Then folder = folder & "\"
    getdir = Dir(folder, vbNormal)
    
    Columns("A:B").ClearContents
    Range("A1") = "Filename"
    Range("B1") = "AA63 value"
    
    
    Do Until getdir = ""
    If Right(getdir, 4) <> "xlsb" Then GoTo nxtfile
    
    Set ConT = CreateObject("ADODB.Connection")
    Set DataT = CreateObject("ADODB.Recordset")
    
    constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & folder & getdir & ";Extended Properties=""Excel 12.0;HDR=No"";"
    sqlstr = "SELECT * FROM [" & "FORM" & "$" & "AA63:AA63" & "];"
    
    
    ConT.Open constr
    DataT.Open sqlstr, ConT, 0, 1, 1
    
    If Not DataT.EOF Then
    Range("A65536").End(xlUp).Offset(1) = getdir
    Range("B65536").End(xlUp).Offset(1).CopyFromRecordset DataT
    End If
    
    DataT.Close
    Set DataT = Nothing
    ConT.Close
    Set ConT = Nothing
    
    nxtfile:
    getdir = Dir
    Loop
    
    End Sub
    Works for me.
    Please click the * below if this helps

+ 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. possible to check for file in multiple folders, then check for values in specific cells?
    By mattheritage in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-04-2014, 08:33 AM
  2. [SOLVED] Importing specific data from multiple text files in a file directory into excel
    By abat in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 07-03-2013, 05:26 PM
  3. [SOLVED] Get file path from a cell, run a check to see if the file has a specific sheet if yes copy
    By Martha44 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-04-2013, 03:35 AM
  4. Replies: 3
    Last Post: 06-11-2009, 07:08 PM
  5. Saving file to specific directory
    By sungen99 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-22-2006, 10:10 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