Results 1 to 4 of 4

Macro - Folder loop to gather info?

Threaded View

  1. #1
    Forum Contributor
    Join Date
    12-18-2012
    Location
    Sweden
    MS-Off Ver
    Office 2016
    Posts
    158

    Macro - Folder loop to gather info?

    Hi all,

    I have about 25 named folders (Agent 1, agent 2, agent 3) etc. and in each folder there is an .xlsx file named just as the folder (folder: Agent 1, XLSX File: Agent 1.xlsx etc.).

    Then in the Summary file (Structure is 25 folders inside a folder called "Silent Coaching" and in the Folder Silent coaching the summary file (Silent Summary) is located). In the Silent Summary.xlsx I have a Macro that looks like this (Sorry for the wall of text. If there is a way to short this down please let me know! ):

    Sub GetDataFromClosedWorkbook()
    Dim wb As Workbook
    Application.ScreenUpdating = False ' turn off the screen updating
    'set the path to the Becke Akerman.xlsx
    Set wb = Workbooks.Open("C:\Users\Coach\Desktop\2014 coaching\Silent Coaching\Agent 1\Agent 1.xlsx", True, True)
    ' the sheet in this workbook to copy to
    With ThisWorkbook.Worksheets("Slask")
    ' read data from the source workbook
    'the range to copy to in this workbook-name of sheet to copy FROM-range in closed workbook to copy
    .Range("B2").Formula = wb.Worksheets("1").Range("D18").Formula
    .Range("B3").Formula = wb.Worksheets("1").Range("D19").Formula
    .Range("B4").Value = wb.Worksheets("1").Range("L18").Value
    .Range("C2").Formula = wb.Worksheets("2").Range("D18").Formula
    .Range("C3").Formula = wb.Worksheets("2").Range("D19").Formula
    .Range("C4").Value = wb.Worksheets("2").Range("L18").Value
    .Range("D2").Formula = wb.Worksheets("3").Range("D18").Formula
    .Range("D3").Formula = wb.Worksheets("3").Range("D19").Formula
    .Range("D4").Value = wb.Worksheets("3").Range("L18").Value
    .Range("E2").Formula = wb.Worksheets("4").Range("D18").Formula
    .Range("E3").Formula = wb.Worksheets("4").Range("D19").Formula
    .Range("E4").Value = wb.Worksheets("4").Range("L18").Value
    .Range("F2").Formula = wb.Worksheets("5").Range("D18").Formula
    .Range("F3").Formula = wb.Worksheets("5").Range("D19").Formula
    .Range("F4").Value = wb.Worksheets("5").Range("L18").Value
    .Range("G2").Formula = wb.Worksheets("6").Range("D18").Formula
    .Range("G3").Formula = wb.Worksheets("6").Range("D19").Formula
    .Range("G4").Value = wb.Worksheets("6").Range("L18").Value
    .Range("H2").Formula = wb.Worksheets("7").Range("D18").Formula
    .Range("H3").Formula = wb.Worksheets("7").Range("D19").Formula
    .Range("H4").Value = wb.Worksheets("7").Range("L18").Value
    .Range("I2").Formula = wb.Worksheets("8").Range("D18").Formula
    .Range("I3").Formula = wb.Worksheets("8").Range("D19").Formula
    .Range("I4").Value = wb.Worksheets("8").Range("L18").Value
    .Range("J2").Formula = wb.Worksheets("9").Range("D18").Formula
    .Range("J3").Formula = wb.Worksheets("9").Range("D19").Formula
    .Range("J4").Value = wb.Worksheets("9").Range("L18").Value
    .Range("K2").Formula = wb.Worksheets("10").Range("D18").Formula
    .Range("K3").Formula = wb.Worksheets("10").Range("D19").Formula
    .Range("K4").Value = wb.Worksheets("10").Range("L18").Value
    .Range("L2").Formula = wb.Worksheets("11").Range("D18").Formula
    .Range("L3").Formula = wb.Worksheets("11").Range("D19").Formula
    .Range("L4").Value = wb.Worksheets("11").Range("L18").Value
    .Range("M2").Formula = wb.Worksheets("12").Range("D18").Formula
    .Range("M3").Formula = wb.Worksheets("12").Range("D19").Formula
    .Range("M4").Value = wb.Worksheets("12").Range("L18").Value
    End With
    wb.Close False ' close the source workbook without saving any changes
    Set wb = Nothing ' free memory
    Application.ScreenUpdating = True ' turn on the screen updating
    'End Sub
    End Sub
    This fills out the information I need from the 12 different sheets from my other workbook.

    Now to what I need to do (NO idea how to do this.) is I want this when the information is gathered from the first file to go to the next folder and open Agent 2.xlsx and so on all the way until the last folder (this can be 20 or 32, no exact number.). I then want this to grab the information But since there are a lot of agents (25 people, all named differently (it wont be Agent 1, agent 2 etc. it will be John Doe, Jane Doe, Martha Stewart etc) I want it to check A1, A6, A11 (Where the agents name will be (for example, in cell A1 there will say "Agent 1" since its his information I want pasted there)) and then post the correct information into the correct cell.

    The example has the agents name in A1, then in A2, A3 and A4 the criteria (Date, Score, Case) and then to the right the pasted information. Same will apply for next agent (agent 2 will be in A6 etc. etc.). Would like it to match the name of the XLSX file it opens to paste in the correct spot if possible?

    It sounds VERY tough from where I am looking but im hoping someone here understands what I want and can help me!

    Thanks in advance for any help anyone here can provide!
    Last edited by Vihral; 11-27-2013 at 03:10 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Can excel gather data from every work book in a folder?
    By McCool in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-22-2013, 06:12 AM
  2. [SOLVED] VBA code to gather data from multiple worksheets in the same folder-Master List
    By lax2734 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-23-2012, 03:07 PM
  3. Using for loop to gather multiple values from different sheets
    By alexwgordon in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-16-2011, 08:08 PM
  4. [SOLVED] formula to gather non-empty cell info
    By J_J in forum Excel General
    Replies: 5
    Last Post: 08-17-2005, 04:05 PM
  5. formula to gather non-empty cell info?
    By J_J in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-17-2005, 08:05 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