Advertisement
YasserKhalil2019

T4676_Transfer Data To Closed Workbook By Employee ID

Mar 8th, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. https://excel-egy.com/forum/t4676
  2. ---------------------------------
  3.  
  4. Sub Transfer_Data_To_Closed_Workbook_By_Employee_ID()
  5. Dim x, wb As Workbook, wsSource As Worksheet, wsTarget As Worksheet, c As Range, tbl As ListObject, newRow As ListRow, c1 As Long, c2 As Long
  6.  
  7. Application.ScreenUpdating = False
  8. Set wsSource = ThisWorkbook.ActiveSheet
  9. Set wb = Workbooks.Open(ThisWorkbook.Path & "\Q.c.xlsx")
  10. Set wsTarget = wb.Worksheets("Overtime")
  11.  
  12. For Each c In wsSource.Range("A7:A" & wsSource.Cells(Rows.Count, 1).End(xlUp).Row)
  13. x = Application.Match(c.Value, wsTarget.Columns(1), False)
  14.  
  15. If Not IsError(x) Then
  16. wsTarget.Range("A" & x).Resize(1, 33).Value = c.Resize(1, 33).Value
  17. c1 = c1 + 1
  18. Else
  19. Set tbl = wsTarget.ListObjects("HR_2")
  20. Set newRow = tbl.ListRows.Add
  21. newRow.Range(1).Resize(1, 33).Value = c.Resize(1, 33).Value
  22. c2 = c2 + 1
  23. End If
  24. Next c
  25.  
  26. wb.Close True
  27. Application.ScreenUpdating = True
  28.  
  29. MsgBox "There Are " & c1 & " Record(s) Updated." & vbCrLf & "There Are " & c2 & " Record(s) Added", 64
  30. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement