I want to execute a VBA macro that iterates through all of the Excel files in a given folder. The macro copies the data from four distinct cells (let's say A2, B3, C5, and D6) that I have labelled Region, DateSales, Sales, and Salesman after opening a single file, pastes it into a master file, and then closes the file.
Since I am not an expert in VBA, I need some assistance. I have found a VBA code, but it does not work.
This is the code I have right now
Sub getDataFromWbs()
Dim wb As Workbook, ws As Worksheet
Dim Region As String
Dim DateSales As Date
Dim Sales As Integer
Dim Salesman As String
Application.ScreenUpdating = False
Set fso = CreateObject("Scripting.FileSystemObject")
'Path to the folder
Set fldr = fso.GetFolder("C:\Users\xxxxx\yyyyyy\Desktop\Sales\")
'Next available row in Master Workbook
y = ThisWorkbook.Sheets("Sheet1").Cells(rows.Count, 1).End(xlUp).Row + 1
'Loop through each file in that folder
For Each wbFile In fldr.files
'Make sure looping only through files ending in .xlsx (Excel files)
If fso.GetExtensionName(wbFile.Name) = "xlsx" Then
'Open current book
Set wb = Workbooks.Open(wbFile.Path)
Region = Sheets(1).Cells(1, 2).Value
DateSales = Sheets(1).Cells(2, 3).Value
Sales = Sheets(1).Cells(3, 5).Value
Salesman = Sheets(1).Cells(4, 6).Value
'Loop through each sheet (ws)