Excel VBA Macro: Extract Data from All Files in a (User Selected) Folder

Поділитися
Вставка
  • Опубліковано 23 лют 2023
  • Excel VBA Macro: Extract Data from All Files in a (User Selected) Folder
    💥Subscribe: / @greggowaffles
    Code:
    Sub grab_data_from_files_in_folder()
    Dim myPath As String
    Dim myFile As String
    Dim FldrPicker As FileDialog
    Dim sh As Worksheet
    Dim i As Integer
    Application.ScreenUpdating = False
    Set sh = ThisWorkbook.Sheets("Team Summary")
    Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
    With FldrPicker
    .Title = "Please Select Folder"
    .AllowMultiSelect = False
    .ButtonName = "Confirm!!"
    If .Show = -1 Then
    myPath = .SelectedItems(1) & "\"
    Else
    End
    End If
    End With
    With sh
    .Cells.ClearContents
    .Cells(1, 1) = "Team Name"
    .Cells(1, 1).Font.Size = 14
    .Cells(1, 1).Font.Bold = True
    .Cells(1, 2) = "Total Sales"
    .Cells(1, 2).Font.Size = 14
    .Cells(1, 2).Font.Bold = True
    End With
    myFile = Dir(myPath)
    i = 2
    Do While myFile <> ""
    Workbooks.Open Filename:=myPath & myFile
    sh.Cells(i, 1) = ActiveWorkbook.Sheets("Team Sales").Cells(1, 2).Text
    sh.Cells(i, 2) = ActiveWorkbook.Sheets("Team Sales").Cells(2, 2).Value
    ActiveWorkbook.Close savechanges:=False
    myFile = Dir
    i = i + 1
    Loop
    Application.ScreenUpdating = True
    End Sub
    #excelmacro #excelvba

КОМЕНТАРІ • 17

  • @alexrosen8762
    @alexrosen8762 Рік тому

    This type of tutorials are extremely useful for many reasons, mostly because it has concrete real life examples attached to it. Big thank you 🙏

    • @greggowaffles
      @greggowaffles  Рік тому +1

      Thanks again for the positive feedback! I’m open to any suggestions

  • @user-wd8hi9gp6w
    @user-wd8hi9gp6w 14 днів тому

    Amazing!!

  • @szewing9038
    @szewing9038 Рік тому

    Hi Greg I learn a lot from you. Your teaching is precise and clear. Thanks so much! Keep it up!!!

  • @RR-kj3sz
    @RR-kj3sz 9 місяців тому

    Thank you!!!

  • @MohAboAbdo
    @MohAboAbdo Рік тому

    Thank you so much Sir

  • @Serg1457
    @Serg1457 Рік тому

    Thanks a lot it is really useful! But if you need to gather date for 10-15 columns is it going to be any different and if every time there will be a new file with data, let's say new team every time, can we keep adding info to already existing values? Thanks a lot

  • @raymartbalakit3062
    @raymartbalakit3062 6 місяців тому

    @greggowaffles what if I have different workbooks with different test results? and each sheet of the test result for each file has also unique name? How to make a macro that can extract that.

  • @brianwarner493
    @brianwarner493 Рік тому

    Would love to see this extract all data from all word docs in a selected folder & subfolders

  • @janineacoba9710
    @janineacoba9710 Рік тому

    Hi, how to copy all starting from a desired row

  • @gabriellesmith5540
    @gabriellesmith5540 Рік тому

    Hi! I got an error message when I tried and it was because of the “Set sh” line

  • @GabbsOnAir
    @GabbsOnAir 6 місяців тому

    How do you fix the code if the sheet names are different every time? For example, instead of "Team Sales" you have "Team Red Sales", "Team Pink Sales", etc

    • @burakguner6815
      @burakguner6815 3 місяці тому

      Hi, have you found out a solution for this?

  • @tierratako
    @tierratako 8 місяців тому +1

    Mine is only opening the first file. Any suggestions?

    • @jayant107
      @jayant107 7 місяців тому

      Same here and it's stuck in a loop!