Topic Closed
Topic Closed
It looks like you are doing pretty good here and got the hard stuff finished (referencing the other workbooks and closing them)
To help with your logic, you could try something like this:
If wsh1.Range("E1").Value = wsh2.Range("A1").Value Then
Next step is to check if Column C/D/etc. has a value:
If wsh2.Range("C1").Value <> "" Then
Do this for each column you want to check.
Then copy/paste:
wsh1.Range("E1").Copy wsh2.Range("C1")
You will need to figure out which row to paste the data into, which is done depending on how you want the macro to copy the data (overwritting the previous entry or not), but this should give you the framework that you need to finish your macro.
Sub Mysub
dim wbk1 as workbook
dim wbk2 as workbook
Application.ScreenUpdating = False
Set wbk1 = Workbooks.Open(ThisWorkbook.Path & "\target1.xlsx")
Set wsh1 = wbk1.Worksheets(1)
Set wbk2 = Workbooks.Open(ThisWorkbook.Path & "\target2.xlsx")
Set wsh2 = wbk2.Worksheets(1)
If wsh1.Range("E1").Value = wsh2.Range("A1").Value Then
If wsh2.Range("C1").Value <> "" Then
wsh1.Range("E1").Copy wsh2.Range("C1")
end if
Application.DisplayAlerts = False
wbk1.Close SaveChanges:=True
wbk2.Close SaveChanges:=True
Application.DisplayAlerts = True
Application.ScreenUpdating = True
end sub
Sub Mysub()
Dim wbk1 As Workbook
Dim wbk2 As Workbook
Application.ScreenUpdating = False
Set wbk1 = Workbooks.Open(ThisWorkbook.Path & "\ap.xls")
Set wsh1 = wbk1.Worksheets(1)
Set wbk2 = Workbooks.Open(ThisWorkbook.Path & "\PL.xlsx")
Set wsh2 = wbk2.Worksheets(1)
If wsh1.Range("E1").Value = wsh2.Range("A1").Value Then
If wsh2.Range("C1").Value <> "" Then
wsh1.Range("E1").Copy wsh2.Range("C1")
End If
End If
Application.DisplayAlerts = False
wbk1.Close SaveChanges:=True
wbk2.Close SaveChanges:=True
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub