I'm trying to copy Range A:3 to A:x (where x is the number of rows in the table "AgentName") from sheet "AgentName" However, whenever I try to copy the range with a variable in it, it gives me the Error 1004. I've read through everything I could find. Here's two common ones I've tried.
Worksheets("AgentName").Range("A3:A"&x).copy
Worksheets("AgentName").Range(Sheets("AgentName").Cells(3, 1), Sheets("AgentName").Cells(x, 1)).Copy
^I've tried it without the Sheets, with just cells, with cells and range together.
Here's a shortened version of the code:
Private Sub CommandButton1_Click()
'CountRows in AgentName Table
Dim myWorkSheet As Worksheet, myTable As ListObject, x As Long
Set myWorkSheet = ActiveWorkbook.Worksheets("AgentName")
Set myTable = myWorkSheet.ListObjects("AgentName")
x = myTable.DataBodyRange.Rows.Count
'Specific Forms for All Agents (Motivated)
If Range("B3").Value = "All Agents" And Range("C3").Value = "Motivated" Then
Worksheets("Other Forms").Range("A1:H2").Copy
Worksheets("Master").Range("B6:I7").PasteSpecial
Worksheets("AgentName").Range(Sheets("AgentName").Cells(3, 1), Sheets("AgentName").Cells(x, 1)).Copy
Worksheets("Master").Range("B8:B13").PasteSpecial
Range("B6:I13").Borders.LineStyle = xlContinuous
End If
End Sub