0

I am trying to paste a range into a sheet which has it's name defined by a cell in excel. This is the code

Sub copynotes()
Dim xcopy, xpaste As Range
Dim Analystname As String

Analystname = Sheets("Admin").Range("g2")
 'Sheets(Analystname).Select

xcopy = Range("j2:n2")
xpaste = Sheets(Analystname).Range("a2")
xcopy.Copy Destination:=xpaste
End Sub

I receive an error at "xpaste Sheets(Analystname).Range("a2")"

(Object variable or with block variable not set)

However the sheet seems to be properly defined since vba can select it.

Could you please help me understand what is the issue with the code?

Thank you for your time

SJR
  • 22,986
  • 6
  • 18
  • 26
fedone
  • 55
  • 7
  • 1
    `Set xpaste = Sheets(Analystname).Range("a2")`. and `Set xcopy = Range("j2:n2")` – SJR May 05 '23 at 17:24
  • 1
    `Dim xcopy as Range, xpaste As Range` - you should specify both. – SJR May 05 '23 at 17:24
  • 1
    https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/set-statement – SJR May 05 '23 at 17:56

0 Answers0