A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Hi, Jack Ledom
The error occurs at ActiveSheet.Paste because the macro repeatedly selects worksheets and relies on Excel’s clipboard. The screenshot confirms that the worksheet Paste method is failing, and this method depends on a valid current selection unless a destination is supplied.
Here are some suggestions you can try:
Replace the loop with direct, fully qualified range operations, which avoids Select, ActiveSheet, and clipboard-based pasting:
Option Explicit
Sub Update()
Dim wsS As Worksheet, wsDB As Worksheet
Dim i As Long, NumPlaying As Long, DBRow As Long
Dim datePlay As Variant
Set wsS = ThisWorkbook.Worksheets("Scores")
Set wsDB = ThisWorkbook.Worksheets("Player DB")
datePlay = wsS.Range("X1").Value
NumPlaying = wsS.Cells(3, 31).Value
Application.ScreenUpdating = False
For i = 1 To NumPlaying
DBRow = CLng(wsS.Cells(i + 2, 32).Value)
If DBRow > 0 Then
wsDB.Range(wsDB.Cells(DBRow, 8), wsDB.Cells(DBRow, 26)).Copy _
Destination:=wsDB.Cells(DBRow, 9)
wsDB.Cells(DBRow, 8).Value = wsS.Range("Z" & i + 2).Value
wsDB.Range(wsDB.Cells(DBRow, 30), wsDB.Cells(DBRow, 48)).Copy _
Destination:=wsDB.Cells(DBRow, 31)
wsDB.Cells(DBRow, 30).Value = wsS.Range("AD" & i + 2).Value
wsDB.Range(wsDB.Cells(DBRow, 51), wsDB.Cells(DBRow, 69)).Copy _
Destination:=wsDB.Cells(DBRow, 52)
wsDB.Cells(DBRow, 51).Value = datePlay
End If
Next i
wsS.Cells(1, 21).Value = Date
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
Also confirm that every value in column AF is a valid Player DB row number.
Thank you for your patience in reading, I hope this information has been helpful to you.
If the answer is helpful, please click "Yes" and kindly upvote it. If you have extra questions about this answer, please click "Comment."
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.