Hey Guys,
I know you have gotten this one a bunch before, but I can't find a way to do the couple things I need this to do. I'm really close however, so it shouldn't take more than 5 minutes hopefully.
What I need.
Open multiple files at one time, copy and paste certain cells in those files, to the corresponding cells in my master file. It cannot overwrite the old data lines, it simply needs to paste the new information in the master below the old information. Then close the files.
here's what I have so far, this code works... it's missing 2 things.
Does not open multiple files and does not paste new information below old information.
Sub ImportData()
Dim strFile As String
MsgBox "Select Expense Reports"
strFile = Application.GetOpenFilename("Excel-files,*.xlsm ; *.xls ; *.xlsx", _
1, "Select Expense Reports", , False)
If strFile = "False" Then Exit Sub
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim oWorkBook As Workbook
Dim oSheet As Worksheet
Dim oMaster As Worksheet
Dim i As Long
On Error Resume Next
Set oMaster = ThisWorkbook.Worksheets("Master")
Set oWorkBook = Workbooks.Open(strFile, ReadOnly:=True)
Set oSheet = oWorkBook.Worksheets("End Report")
ThisWorkbook.Save
i = oMaster.Cells.SpecialCells(xlCellTypeLastCell).Row
If i > 1 Then
oMaster.Range("A:J" & i).Interior.Pattern = xlNone
End If
i = oSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
oMaster.Range("A4").Value = oSheet.Range("C13").Value
oMaster.Range("B4").Value = oSheet.Range("F8").Value
oMaster.Range("C4").Value = oSheet.Range("F9").Value
oMaster.Range("D4").Value = oSheet.Range("C9").Value
oMaster.Range("E4").Value = oSheet.Range("C10").Value
oMaster.Range("F4").Value = oSheet.Range("C14").Value
oMaster.Range("G4").Value = oSheet.Range("C16").Value
oMaster.Range("H4").Value = oSheet.Range("C17").Value
oMaster.Range("I4").Value = oSheet.Range("C18").Value
oMaster.Range("J4").Value = oSheet.Range("C19").Value
oMaster.Range("K4").Value = oSheet.Range("C20").Value
oMaster.Range("L4").Value = oSheet.Range("C22").Value
oMaster.Range("M4").Value = oSheet.Range("F12").Value
oWorkBook.Close (False)
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Please Help
Thank you!
I know you have gotten this one a bunch before, but I can't find a way to do the couple things I need this to do. I'm really close however, so it shouldn't take more than 5 minutes hopefully.
What I need.
Open multiple files at one time, copy and paste certain cells in those files, to the corresponding cells in my master file. It cannot overwrite the old data lines, it simply needs to paste the new information in the master below the old information. Then close the files.
here's what I have so far, this code works... it's missing 2 things.
Does not open multiple files and does not paste new information below old information.
Sub ImportData()
Dim strFile As String
MsgBox "Select Expense Reports"
strFile = Application.GetOpenFilename("Excel-files,*.xlsm ; *.xls ; *.xlsx", _
1, "Select Expense Reports", , False)
If strFile = "False" Then Exit Sub
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim oWorkBook As Workbook
Dim oSheet As Worksheet
Dim oMaster As Worksheet
Dim i As Long
On Error Resume Next
Set oMaster = ThisWorkbook.Worksheets("Master")
Set oWorkBook = Workbooks.Open(strFile, ReadOnly:=True)
Set oSheet = oWorkBook.Worksheets("End Report")
ThisWorkbook.Save
i = oMaster.Cells.SpecialCells(xlCellTypeLastCell).Row
If i > 1 Then
oMaster.Range("A:J" & i).Interior.Pattern = xlNone
End If
i = oSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
oMaster.Range("A4").Value = oSheet.Range("C13").Value
oMaster.Range("B4").Value = oSheet.Range("F8").Value
oMaster.Range("C4").Value = oSheet.Range("F9").Value
oMaster.Range("D4").Value = oSheet.Range("C9").Value
oMaster.Range("E4").Value = oSheet.Range("C10").Value
oMaster.Range("F4").Value = oSheet.Range("C14").Value
oMaster.Range("G4").Value = oSheet.Range("C16").Value
oMaster.Range("H4").Value = oSheet.Range("C17").Value
oMaster.Range("I4").Value = oSheet.Range("C18").Value
oMaster.Range("J4").Value = oSheet.Range("C19").Value
oMaster.Range("K4").Value = oSheet.Range("C20").Value
oMaster.Range("L4").Value = oSheet.Range("C22").Value
oMaster.Range("M4").Value = oSheet.Range("F12").Value
oWorkBook.Close (False)
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Please Help
Thank you!
Last edited: