Results 1 to 1 of 1

Creating a code to count and extract data from template to master file

Threaded View

  1. #1
    Registered User
    Join Date
    12-10-2015
    Location
    Michigan
    MS-Off Ver
    2010
    Posts
    52

    Creating a code to count and extract data from template to master file

    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
    Last edited by B_Jarbs; 01-07-2016 at 11:34 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA code to insert data from multiple .txt files into one output file template file
    By psmith33 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-04-2015, 02:49 PM
  2. [SOLVED] exporting data from master file to template file (autopopulate a template)
    By Gti182 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-06-2014, 11:41 AM
  3. Macro to extract a tab from one file, add it to a master template file and then save as
    By SweetSorcery in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-03-2014, 11:36 AM
  4. Replies: 2
    Last Post: 02-14-2014, 01:39 PM
  5. [SOLVED] Exporting data from master file to pre-populate many excel files from a template
    By Gti182 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 08-07-2013, 07:52 AM
  6. Creating Workbooks from a Master with template
    By bradwatt in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-27-2011, 02:52 AM
  7. Seting a Constant (via code) when creating a new file based on a template
    By Conan Kelly in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-15-2005, 01:05 PM

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