Ok so I have been working on this code for a few weeks now. Basically I have to write a code where I choose a folder and within that folder multiple excel files are opened and certain data is copied from certain cells and placed into a master file. An issue comes when the template file is not 100% identical throughout all the files. Basically for a certain part of the code instead of copying the cell data I want to take the raw data, count it and then place it into the master file.
Attachment 438974
So this is the "template file" I need to sort the data in Range F and extract the totals into the master file.
master findings.PNG
This is where they need to go.
Option Explicit
Sub ExtrData()
Dim MyFolder As String 'Store the folder selected by the user
Dim sFile As String
Dim wk As Workbook
Dim i As Integer
Application.ScreenUpdating = False
'Display the folder picker dialog box for user selection of directory
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Please select a folder"
.Show
.AllowMultiSelect = False
If .SelectedItems.Count = 0 Then
MsgBox "You did not select a folder"
Exit Sub
End If
MyFolder = .SelectedItems(1) & "\"
End With
'Dir finds the files in the selected folder,
sFile = Dir(MyFolder)
If sFile = "" Then
MsgBox "No files matching set criteria found"
Exit Sub
End If
i = 2
Do While sFile <> ""
Set wk = Workbooks.Open(MyFolder & sFile)
On Error Resume Next
Sheets("Deckblatt, Cover Sheet").Activate
If Err.Number = 9 Then
wk.Close SaveChanges:=False
GoTo skipper
End If
ThisWorkbook.Sheets("Sheet1").Range("A" & i) = sFile
ThisWorkbook.Sheets("Sheet1").Range("B" & i) = MyFolder
Range("E14").Copy
ThisWorkbook.Sheets("Sheet1").Range("C" & i).PasteSpecial xlPasteValues
Range("F3").Copy
ThisWorkbook.Sheets("Sheet1").Range("D" & i).PasteSpecial xlPasteValues
Range("D3").Copy
ThisWorkbook.Sheets("Sheet1").Range("E" & i).PasteSpecial xlPasteValues
Range("D7").Copy
ThisWorkbook.Sheets("Sheet1").Range("F" & i).PasteSpecial xlPasteAll
Range("D11").Copy
ThisWorkbook.Sheets("Sheet1").Range("G" & i).PasteSpecial xlPasteAll
Range("E7").Copy
ThisWorkbook.Sheets("Sheet1").Range("H" & i).PasteSpecial xlPasteAll
Range("E11").Copy
Application.CutCopyMode = False
wk.Close SaveChanges:=False
i = i + 1
skipper:
sFile = Dir()
Loop
Application.ScreenUpdating = True
End Sub
This is the code I have now(minus some copies of cells (80+ total))
In this code I am copying values from the coversheet vs protocol. for the data I need it is in protocol.
I know this is not the clearest of descriptions but any thing will help and I can clear up any confusion if need be.
P.S. I am not a very proficient coder. I have some C++ knowledge and a little bit of VBA
Thanks
Branden
Bookmarks