Sub rozek_MasterSheet_UpdaterV1()
'
Dim DataRowCounter As Long
Dim DestinationWorkbookSheetToCopyToRow As Long
Dim LastRowDestinationWorkbookSheetToCopyTo As Long
Dim MaxNumberOfDataFilesToBeUsed As Long
Dim SourceFileNumber As Long
Dim DataDate As String
Dim SourceWorkbookSheetName As String
Dim UserSelectedDataFileToOpen As String
Dim SourceWorkbook As Workbook
Dim DestinationWorkbookSheetToCopyTo As Worksheet
Dim SourceWorkbookSheetToCopyFrom As Worksheet
'
MaxNumberOfDataFilesToBeUsed = 3 ' <--- Set this to the # of data files that you want to get data from
SourceWorkbookSheetName = "Sheet1" ' <--- Set this to the sheet name to copy data from
Set DestinationWorkbookSheetToCopyTo = ThisWorkbook.Worksheets("MasterSheet") ' <--- Set this to the sheet name to copy data to
'
With DestinationWorkbookSheetToCopyTo.Range("A1:D1") ' Insert and Bold the Header for Destination Sheet
.Value = Array("DATE", "NAME", "PRESS", "TEMP")
.Font.Bold = True
End With
'
For SourceFileNumber = 1 To MaxNumberOfDataFilesToBeUsed ' Get data file paths/names Loop
UserSelectedDataFileToOpen = Application.GetOpenFilename(Title:="Select File #" & SourceFileNumber & " of " & MaxNumberOfDataFilesToBeUsed & " files to Import Data from", FileFilter:="Excel Files (*.xls*), *xls*")
'
If UserSelectedDataFileToOpen = "False" Then Exit Sub ' Check to see if user clicked 'Cancel' or the 'X' button
'
Set SourceWorkbook = Workbooks.Open(UserSelectedDataFileToOpen) ' Open the selected data workbook
Set SourceWorkbookSheetToCopyFrom = SourceWorkbook.Worksheets(SourceWorkbookSheetName) ' Set the source workbook sheet name to copy data from
'
LastRowDestinationWorkbookSheetToCopyTo = DestinationWorkbookSheetToCopyTo.Cells.Find("*", , xlFormulas, , xlByRows, xlPrevious).Row
LastRowSourceWorkbookSheetToCopyFrom = SourceWorkbookSheetToCopyFrom.Cells.Find("*", , xlFormulas, , xlByRows, xlPrevious).Row
'
DataDate = SourceWorkbookSheetToCopyFrom.Range("B1").Text ' Grab the date from the data file worksheet
For DataRowCounter = 3 To LastRowSourceWorkbookSheetToCopyFrom ' Loop through the rows of data to copy from
DestinationWorkbookSheetToCopyToRow = LastRowDestinationWorkbookSheetToCopyTo + DataRowCounter - 2 ' Set the row number to copy data to
'
DestinationWorkbookSheetToCopyTo.Range("A" & DestinationWorkbookSheetToCopyToRow) = DataDate
DestinationWorkbookSheetToCopyTo.Range("B" & DestinationWorkbookSheetToCopyToRow) = SourceWorkbookSheetToCopyFrom.Range("A" & DataRowCounter)
DestinationWorkbookSheetToCopyTo.Range("C" & DestinationWorkbookSheetToCopyToRow) = SourceWorkbookSheetToCopyFrom.Range("C" & DataRowCounter)
DestinationWorkbookSheetToCopyTo.Range("D" & DestinationWorkbookSheetToCopyToRow) = SourceWorkbookSheetToCopyFrom.Range("D" & DataRowCounter)
Next
'
SourceWorkbook.Close savechanges:=False ' Close the data workbook without saving changes
Next
'
LastRowDestinationWorkbookSheetToCopyTo = DestinationWorkbookSheetToCopyTo.Cells.Find("*", , xlFormulas, , xlByRows, xlPrevious).Row
'
With DestinationWorkbookSheetToCopyTo.Range("A1:D" & LastRowDestinationWorkbookSheetToCopyTo) ' Center all the data in the Destination sheet
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
End Sub