Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://excel-egy.com/forum/t4676
- ---------------------------------
- Sub Transfer_Data_To_Closed_Workbook_By_Employee_ID()
- 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
- Application.ScreenUpdating = False
- Set wsSource = ThisWorkbook.ActiveSheet
- Set wb = Workbooks.Open(ThisWorkbook.Path & "\Q.c.xlsx")
- Set wsTarget = wb.Worksheets("Overtime")
- For Each c In wsSource.Range("A7:A" & wsSource.Cells(Rows.Count, 1).End(xlUp).Row)
- x = Application.Match(c.Value, wsTarget.Columns(1), False)
- If Not IsError(x) Then
- wsTarget.Range("A" & x).Resize(1, 33).Value = c.Resize(1, 33).Value
- c1 = c1 + 1
- Else
- Set tbl = wsTarget.ListObjects("HR_2")
- Set newRow = tbl.ListRows.Add
- newRow.Range(1).Resize(1, 33).Value = c.Resize(1, 33).Value
- c2 = c2 + 1
- End If
- Next c
- wb.Close True
- Application.ScreenUpdating = True
- MsgBox "There Are " & c1 & " Record(s) Updated." & vbCrLf & "There Are " & c2 & " Record(s) Added", 64
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement