Search code examples
excelvbauserform

Why is my copy and paste code getting an "Object Required" error?


When I run my code to copy and paste data from my UserForm to my worksheet, I am getting an "Object Required" error. I'm not really sure why. Is the .Copy function not working with a value or is it on my UserForm? Is there a different function I should be using or am I just mistyping something in my code?

Here is my code:


Dim wsDest As Worksheet
Dim lCopyLastRow As Long
Dim lDestLastRow As Long

  Set wsDest = ThisWorkbook.Worksheets("backend")

lDestLastRow = wsDest.Cells(wsDest.Rows.Count, "I").End(xlUp).Offset(1).Row

SalesForm.BHSDDATEIF.Value.Copy _
 wsDest.Range("I" & lDestLastRow)

SalesForm.BHSDREPNUMBERIF.Value.Copy _
 wsDest.Range("H" & lDestLastRow)
 
SalesForm.BHSDMAINNUMBERLF.Value.Copy _
 wsDest.Range("S" & lDestLastRow)
 
SalesForm.BHSDTAPNAMELF.Value.Copy _
 wsDest.Range("T" & lDestLastRow)
 
SalesForm.BHSDCOMPANYNAMELF.Value.Copy _
 wsDest.Range("U" & lDestLastRow)
 
SalesForm.BHSDEMAILLF.Value.Copy _
 wsDest.Range("V" & lDestLastRow)
 
SalesForm.BHSDADDRESSLF.Value.Copy _
 wsDest.Range("W" & lDestLastRow)
 
SalesForm.BHSDCSZLF.Value.Copy _
 wsDest.Range("X" & lDestLastRow)
 
SalesForm.BHSDAMOUNTIF.Value.Copy _
 wsDest.Range("F" & lDestLastRow)
 
SalesForm.BHSDCCAMOUNTIF.Value.Copy _
 wsDest.Range("G" & lDestLastRow)
 
SalesForm.BHSDCARDNUMIF.Value.Copy _
 wsDest.Range("B" & lDestLastRow)
 
SalesForm.BHSDEXPIF.Value.Copy _
 wsDest.Range("C" & lDestLastRow)
 
SalesForm.BHSDCVVIF.Value.Copy _
 wsDest.Range("D" & lDestLastRow)
 
SalesForm.BHSDZIPIF.Value.Copy _
 wsDest.Range("E" & lDestLastRow)
 
SalesForm.BHSRUNDATEIF.Value.Copy _
 wsDest.Range("A" & lDestLastRow)
 
SalesForm.BHSDNOTESIF.Value.Copy _
 wsDest.Range("M" & lDestLastRow)
 
 End Sub```

Solution

  • SalesForm.BHSDDATEIF.Value is not an object, so it doesn't have a Copy method.

    Instead of copy/paste you should just assign the values directly to the range.

    Eg:

    wsDest.Range("I" & lDestLastRow) = SalesForm.BHSDDATEIF.Value