Macro to pull in data from other excel sheets in a folder?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi everyone,

Ok so what i'm trying to do is this.

I have a document Called "Master Dashboard" with a sheet Called "Projects Data"

In this sheet Row1 has Headers of Project1,Project2 etc up to Project20 (A1:U1)

I have a Folder on my desktop called "Projects"
in this folder are up to 20 excel docs (All XLSM)

I want a macro that when run does this

Goes to Folder "Projects" and checks there are no more than 20 docs in folder,
If there are Message box "To Many Folders" and exit sub.

if not Open each folder, copy the data in Sheet"Control" Range(M1:M97) and paste it in "Master Dashboard" Sheet "Projects Data"
so the first would go Under Project1 in A2 next Project2 for however many projects there are.

Please help if you can

Thanks

Tony
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi,
Can anyone help me on this? i've been trying but still stuck
Tony
 
Upvote 0
Try:
Code:
Sub CopyRange()
    Application.ScreenUpdating = False
    Dim wkbDest As Workbook, wkbSource As Workbook
    Set wsDest = ThisWorkbook.Sheets("Projects Data")
    Dim LastRow As Long, sFile As String, sFolder As String
    Dim lColumn As Long
    lColumn = 1
    sFolder = (CreateObject("WScript.Shell").specialfolders("Desktop") & "\Projects\")
    sFile = Dir(sFolder & "*.xlsm")
    Do While sFile <> ""
        j = j + 1
        sFile = Dir
    Loop
    If j > 20 Then
        MsgBox ("There are more than 20 files in the folder.")
        Exit Sub
    End If
    ChDir sFolder
    strExtension = Dir(sFolder & "*.xlsm")
    Do While strExtension <> ""
        Set wkbSource = Workbooks.Open(strPath & strExtension)
        With wkbSource
            .Sheets("Control").Range("M1:M97").Copy wsDest.Cells(2, lColumn)
            lColumn = lColumn + 1
            .Close savechanges:=False
        End With
        strExtension = Dir
    Loop
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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