Bobbybazza
New Member
- Joined
- Mar 7, 2013
- Messages
- 5
Hi all, thanks for your time:
This is really some additional help to an earlier thread that has provided almost what I want.
This thread:
VBA to extract data from multiple files in a folder
This is extracting the information almost as I want it. I have files in a folder, all have a similar format with the first 10 rows of each worksheet in the individual workbooks (they only have 1) having data that identifies where the data contained in row 11 onwards comes from.
What I would like to do is add the information held in Cell A8 and Cell D4 to the end of each row of the data that is extracted from that particular workbook and consolidated in the master as an identifier. It looks like the data copying over is done in one go and not line by line so I'm not sure how to go from here really. (sorry, a bit of a newbie)
The code I'm using adapted for my needs is:
Any help would be appreciated.
Thanks
This is really some additional help to an earlier thread that has provided almost what I want.
This thread:
VBA to extract data from multiple files in a folder
This is extracting the information almost as I want it. I have files in a folder, all have a similar format with the first 10 rows of each worksheet in the individual workbooks (they only have 1) having data that identifies where the data contained in row 11 onwards comes from.
What I would like to do is add the information held in Cell A8 and Cell D4 to the end of each row of the data that is extracted from that particular workbook and consolidated in the master as an identifier. It looks like the data copying over is done in one go and not line by line so I'm not sure how to go from here really. (sorry, a bit of a newbie)
The code I'm using adapted for my needs is:
VBA Code:
Sub Consolidate()
'Author: Jerry Beaucaire'
'Date: 9/15/2009 (2007 compatible) (updated 4/29/2011)
'Summary: Merge files in a specific folder into one master sheet (stacked)
' Moves imported files into another folder
Dim fName As String, fpath As String, fPathDone As String
Dim LR As Long, NR As Long
Dim wbData As Workbook, wsMaster As Worksheet
'Setup
Application.ScreenUpdating = False 'speed up macro execution
Application.EnableEvents = False 'turn off other macros for now
Application.DisplayAlerts = False 'turn off system messages for now
Set wsMaster = ThisWorkbook.Sheets("Master") 'sheet report is built into
With wsMaster
If MsgBox("Clear the old data first?", vbYesNo) = vbYes Then
Cells.Select
Selection.UnMerge
.UsedRange.Offset(1).EntireRow.Clear
NR = 2
Else
NR = .Range("A" & .Rows.Count).End(xlUp).Row + 1 'appends data to existing data
End If
'Path and filename (edit this section to suit)
fpath = "C:\Consolidate\" 'remember final \ in this string
fPathDone = fpath & "Imported\" 'remember final \ in this string
On Error Resume Next
MkDir fPathDone 'creates the completed folder if missing
On Error GoTo 0
fName = Dir(fpath & "*.xls*") 'listing of desired files, edit filter as desired
'Import a sheet from found files
Do While Len(fName) > 0
If fName <> ThisWorkbook.Name Then 'don't reopen this file accidentally
Set wbData = Workbooks.Open(fpath & fName) 'Open file
'This is the section to customize, replace with your own action code as needed
LR = Range("A" & Rows.Count).End(xlUp).Row 'Find last row
Range("A11:A" & LR).EntireRow.Copy .Range("A" & NR)
wbData.Close False 'close file
NR = .Range("A" & .Rows.Count).End(xlUp).Row + 1 'Next row
Name fpath & fName As fPathDone & fName 'move file to IMPORTED folder
fName = Dir 'ready next filename
End If
Loop
End With
Any help would be appreciated.
Thanks