Good morning,
I'm trying to get a VBA code that will copy data from sheet Caddy and paste it to destination sheet Analysis. Copy columns A through C from sheet Caddy and paste them to Analysis B through D, starting on row 2. And column D through G, and paste it to L through O. But I'm getting run time error 9 on "Set wsCaddy= ThisWorkbook.Sheets ("Caddy"). I do have the sheet name "Caddy" on the last tab.
I'm trying to get a VBA code that will copy data from sheet Caddy and paste it to destination sheet Analysis. Copy columns A through C from sheet Caddy and paste them to Analysis B through D, starting on row 2. And column D through G, and paste it to L through O. But I'm getting run time error 9 on "Set wsCaddy= ThisWorkbook.Sheets ("Caddy"). I do have the sheet name "Caddy" on the last tab.
VBA Code:
Dim wsSource As Worksheet
Dim wsDest As Worksheet
Dim lastRow As Long
' Set references to the source and destination sheets
[COLOR=rgb(226, 80, 65)] Set wsSource = ThisWorkbook.Sheets("Caddy")[/COLOR]
Set wsDest = ThisWorkbook.Sheets("Analysis")
' Determine the last row with data in column A on the source sheet
lastRow = wsSource.Cells(wsSource.Rows.Count, "A").End(xlUp).Row
' Copy columns A through C from the source sheet
wsSource.Range("A1:C" & lastRow).Copy
' Paste the copied data into the destination sheet starting at row 2, column B
wsDest.Range("B2").PasteSpecial Paste:=xlPasteValues
' Copy columns D through G from the source sheet
wsSource.Range("D1:G" & lastRow).Copy
' Paste the copied data into the destination sheet starting at row 2, column L
wsDest.Range("L2").PasteSpecial Paste:=xlPasteValues
' Clear Clipboard to remove marching ants
Application.CutCopyMode = False
End Sub