Tentei este código, não funciona.
Sub importLEs()
With Excel.Application
.ScreenUpdating = False
.Calculation = Excel.xlCalculationManual
.EnableEvents = False
End With
Dim filename As String
Dim ManagerLEs As Workbook
Dim ProjectLEs As Workbook
Set ProjectLEs = ThisWorkbook
'open file that you are importing data from
filename = Application.GetOpenFilename("Word files (*.xlsx),*.xlsx", , "Browse for file containing table to be imported")
If filename = Empty Then
Exit Sub
End If
Set ManagerLEs = Application.Workbooks.Open(filename)
Dim first_blank_row As Long
first_blank_row = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
starting_row = 4
Dim r As Long
Dim rr As Long
r = starting_row
rr = 4
firstname = ManagerLEs.ActiveSheet.Range("a" & r).Value
projectname = ManagerLEs.ActiveSheet.Range("d" & r).Value
mastername = ProjectLEs.Worksheets("Template").Range("a" & rr).Value
masterproject = ProjectLEs.Worksheets("Template").Range("d" & rr).Value
Do While firstname <> 0
'counter to check if a row is updated
flag = False
Do While mastername <> 0
If mastername = firstname And masterproject = projectname Then
'update existing line of main file
For c = 10 To 57
ProjectLEs.Worksheets("Template").Cells(rr, c) = ManagerLEs.Worksheets("LEs").Cells(r, c)
Next c
flag = True
Exit Do
End If
Loop
'if data does not exist, append data to the end of main file
If flag = False Then
For c = 1 To 57
ProjectLEs.Worksheets("Template").Cells(first_blank_row, c) = ManagerLEs.Worksheets("LEs").Cells(r, c)
Next c
End If
first_blank_row = first_blank_row + 1
rr = rr + 1
r = r + 1
firstname = ManagerLEs.ActiveSheet.Range("a" & r).Value
projectname = ManagerLEs.ActiveSheet.Range("d" & r).Value
mastername = ProjectLEs.Worksheets("Template").Range("a" & rr).Value
masterproject = ProjectLEs.Worksheets("Template").Range("d" & rr).Value
Loop
With Excel.Application
.ScreenUpdating = True
.Calculation = Excel.xlAutomatic
.EnableEvents = True
End With
End Sub
Precisa de um pouco mais de ajuda.