Querying a single cell from multiple workbooks

pbennall

New Member
Joined
Feb 12, 2018
Messages
1
I have a large number of workbooks all created from the same template file. They are all formatted in an identical manner, and each worksheet has a timestamp in cell A4 that I'm interested in extracting.

I'm trying to consolidate the filename and timestamp (cell ref A4) from each worksheet into a single table. Ideally the output table would look something like this:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Filename[/TD]
[TD]Timestamp[/TD]
[/TR]
[TR]
[TD]Example_FileA.xls[/TD]
[TD]01/01/2018 03:45[/TD]
[/TR]
[TR]
[TD]Example_FileB.xls[/TD]
[TD]01/02/2018 14:24[/TD]
[/TR]
[TR]
[TD]...[/TD]
[TD]...[/TD]
[/TR]
</tbody>[/TABLE]

Any advice on how to do this with VBA or PowerQuery? My understanding is that I should be able to do this quite easily with Power Query, but it's pretty new to me.

I'm using Office 2010.

Thanks in advance!
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
paste this code into a module,
set your details :
the folder to get the files: getValInAllFilesInDir "c:\folder"

the run: ScanAllFilesInFolder

Code:
  'store all the values in the A column.  Avg at the end.
'-------------
Public Sub ScanAllFilesInFolder()
'-------------

Range("A1").Select
getValInAllFilesInDir "c:\folder\"

End Sub

'-------------
Private Sub getValInAllFilesInDir(ByVal pvDir)
'-------------
Dim FSO, oFolder, oFile, oRX
Dim sTxt As String, sFile As String


Set FSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = FSO.GetFolder(pvDir)  'use given folder


For Each oFile In oFolder.Files
  If InStr(oFile.Name, ".xls") > 0 Then
       vFile = pvDir & oFile.Name
       GetValInFile vFile
  End If
Next


Set oFile = Nothing
Set oFolder = Nothing
Set FSO = Nothing
End Sub


'-------------
Private Sub GetValInFile(ByVal pvFile)
'-------------
Dim wb As Workbook

Workbooks.Open pvFile
Set wb = ActiveWorkbook
vVal = wb.Range("A4").Value
wb.Close False

ActiveCell.Offset(0, 0).Value = pvFile
ActiveCell.Offset(0, 1).Value = vVal


ActiveCell.Offset(1, 0).Select   'next row
Set wb = Nothing
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top