Simple copy/paste with worksheet variables

jardenp

Active Member
Joined
May 12, 2009
Messages
373
Office Version
  1. 2019
  2. 2016
  3. 2013
  4. 2011
  5. 2010
Platform
  1. Windows
My copy/paste in the "problem line" below is returning a run time error 1004 Method 'Range' of object '_ Worksheet' failed.

What am I doing wrong? I know that the If statement is true for the first time at row 3045 and that the msgboxes return the correct sheet names when I have those lines uncommented.

Thanks!

VBA Code:
    Dim OWS As Worksheet
        Set OWS = ActiveWorkbook.ActiveSheet
        'MsgBox OWS.Name
    RowS("1:1").copy
    Sheets.Add After:=Sheets(Sheets.Count)
    RowS("1:1").Select
    ActiveSheet.Paste
    ActiveSheet.Name = "AR Transaction Lines"
    Dim ARTL As Worksheet
        Set ARTL = ActiveWorkbook.ActiveSheet
        'MsgBox ARTL.Name
       
    Dim r As Integer 'row counter
    Dim s As Integer '"Split" column
        s = 11
    Dim addrow As Integer 'row counter for adding lines on AR sheet
        addrow = 2
           
    For r = 2 To 3047 'OWS.Range("B1000000").End(xlUp).row

        If OWS.Cells(r, s) = "1120 · Accounts Receivable" Then
            OWS.Range(Cells(r, 1), Cells(r, 13)).copy ARTL.Range(Cells(addrow, 1), Cells(addrow, 13)) '****Problem line****
            addrow = addrow + 1
        End If
       
    Next r
 
Last edited by a moderator:
I will keep that technique in mind for the future. Thanks again.
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,216,211
Messages
6,129,528
Members
449,515
Latest member
lukaderanged

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top