Thomas McLernon
New Member
- Joined
- Nov 22, 2021
- Messages
- 4
- Office Version
- 2021
- 2019
- Platform
- Windows
I am not a competent user of VBA, but I found this code that sort of matches what I want to achieve. I need to remove records from an employee scheduling sheet (when a before year-end "end-date" is inserted in a cell) Leaving only current work schedules on the scheduling sheet, and archiving past schedules to a different sheet. When I messed with the original code, on one attempt it transferred the sheet layout over, but not any data.
Thanks,
Tom McLernon
Option Explicit
Sub Copy_n_Paste()
On Error Resume Next
Dim srchtrm As String
Dim rng As Range, destRow As Long
Dim shtSrc As Worksheet, shtDest As Worksheet
Dim c As Range
Dim i As Integer
Dim Today As Date
With Application
.ScreenUpdating = False
.DisplayStatusBar = False
.Calculation = xlCalculationManual
.EnableEvents = False
End With
Set shtSrc = Sheets("Assign Employees to Schedules") 'source sheet
Set shtDest = Sheets("Schedules Ended") 'destination sheet
destRow = 2 'start copying to this row
'don't scan the entire column...
Set rng = Application.Intersect(shtSrc.Range("D:D"), shtSrc.UsedRange)
For Each c In rng.Cells
If c.Value = "Date" Then
c.EntireRow.Copy shtDest.Cells(destRow, 1)
destRow = destRow + 1
End If
Next
With Application
.ScreenUpdating = True
.DisplayStatusBar = True
.Calculation = xlCalculationAutomatic
.EnableEvents = True
End With
Application.CutCopyMode = False
Sheets("Assign Employees to Schedules").Range("D1").Select
End Sub
Thanks,
Tom McLernon
Option Explicit
Sub Copy_n_Paste()
On Error Resume Next
Dim srchtrm As String
Dim rng As Range, destRow As Long
Dim shtSrc As Worksheet, shtDest As Worksheet
Dim c As Range
Dim i As Integer
Dim Today As Date
With Application
.ScreenUpdating = False
.DisplayStatusBar = False
.Calculation = xlCalculationManual
.EnableEvents = False
End With
Set shtSrc = Sheets("Assign Employees to Schedules") 'source sheet
Set shtDest = Sheets("Schedules Ended") 'destination sheet
destRow = 2 'start copying to this row
'don't scan the entire column...
Set rng = Application.Intersect(shtSrc.Range("D:D"), shtSrc.UsedRange)
For Each c In rng.Cells
If c.Value = "Date" Then
c.EntireRow.Copy shtDest.Cells(destRow, 1)
destRow = destRow + 1
End If
Next
With Application
.ScreenUpdating = True
.DisplayStatusBar = True
.Calculation = xlCalculationAutomatic
.EnableEvents = True
End With
Application.CutCopyMode = False
Sheets("Assign Employees to Schedules").Range("D1").Select
End Sub