I have a spreadsheet, and I have some code that isn’t working.
I need to copy over rows of data to another sheet based on if column K is populated (with a date).
The code is stopping and I don’t know why (I’m not very good).
I can attach the sheet – the code is:
Private Sub Workbook_Open()
Dim rng As Range, cell As Range, lastRow As Long
Dim wsPaid As Worksheet: Set wsPaid = ThisWorkbook.Worksheets("Paid")
Application.ScreenUpdating = False
If Not Intersect(Target, Me.Columns("K")) Is Nothing Then
Application.EnableEvents = False
For Each cell In Target
If IsDate(cell.Value) Then
Set rng = Intersect(Target.EntireRow, Me.Range("A:M"))
lastRow = wsPaid.Cells(wsPaid.Rows.Count, "A").End(xlUp).Row + 1
rng.Copy wsPaid.Range("A" & lastRow)
wsPaid.Cells.Columns.AutoFit
rng.Delete
End If
Next cell
Application.EnableEvents = True
End If
Application.ScreenUpdating = True
End Sub
I tried the code, but it stops at If Not Intersect(Target, Me.Columns(“K”)) Is Nothing Then
so I don’t get far. Column K is the paid column in the sample and the first entry (highlighted) is an example of what I want to go to a second sheet.
I want it to run each time it is opened, and for new entries then to go to the bottom of the second sheet. The sheets are unpaid and paid respectively.
Any help would be appreciated on what I’ve done wrong.
Railea Timms is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.