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

  Рет қаралды 7,454

greggowaffles

greggowaffles

Жыл бұрын

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 Жыл бұрын
Thanks again for the positive feedback! I’m open to any suggestions
@szewing9038
@szewing9038 Жыл бұрын
Hi Greg I learn a lot from you. Your teaching is precise and clear. Thanks so much! Keep it up!!!
@greggowaffles
@greggowaffles Жыл бұрын
Thank you so much!! Will do!!
@user-wd8hi9gp6w
@user-wd8hi9gp6w 20 күн бұрын
Amazing!!
@RR-kj3sz
@RR-kj3sz 9 ай бұрын
Thank you!!!
@MohAboAbdo
@MohAboAbdo Жыл бұрын
Thank you so much Sir
@greggowaffles
@greggowaffles Жыл бұрын
No problem! Thanks for watching!!
@brianwarner493
@brianwarner493 Жыл бұрын
Would love to see this extract all data from all word docs in a selected folder & subfolders
@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.
@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 7 ай бұрын
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 9 ай бұрын
Mine is only opening the first file. Any suggestions?
@jayant107
@jayant107 8 ай бұрын
Same here and it's stuck in a loop!
Copying Data from User Selected Files Using GetOpenFilename
10:26
Excel Macro Mastery
Рет қаралды 19 М.
Excel VBA Macro: List All Files (From a Selected Folder)
8:43
greggowaffles
Рет қаралды 9 М.
WORLD'S SHORTEST WOMAN
00:58
Stokes Twins
Рет қаралды 55 МЛН
Mama vs Son vs Daddy 😭🤣
00:13
DADDYSON SHOW
Рет қаралды 43 МЛН
КАК ДУМАЕТЕ КТО ВЫЙГРАЕТ😂
00:29
МЯТНАЯ ФАНТА
Рет қаралды 10 МЛН
No empty
00:35
Mamasoboliha
Рет қаралды 7 МЛН
VBA to BROWSE & COPY Data from SELECTED File in Excel
10:00
Leila Gharani
Рет қаралды 324 М.
How to Get List of File Names in a Folder using Excel
5:40
Excel Weez
Рет қаралды 6 М.
The Ultimate Guide to Copying Data using Excel VBA
31:05
Excel Macro Mastery
Рет қаралды 64 М.
Loop Through All Files in a Folder Using VBA/Macros in Excel
13:41
6 Excel Tools Most Users Never Think to Use (Files Included)
12:34
MyOnlineTrainingHub
Рет қаралды 144 М.
WORLD'S SHORTEST WOMAN
00:58
Stokes Twins
Рет қаралды 55 МЛН