Run-time Error 1004

mezzy01

Board Regular
Joined
Nov 7, 2005
Messages
54
I keep getting run-time error when I run the following code

Public Sub CopyRows()

Sheets("Sheet1").Select
' Find the last row of data
FinalRow = Range("A65536").End(xlUp).Row
' Loop through each row
For x = 2 To FinalRow
' Decide if to copy based on column H
ThisValue = Range("H" & x).Value
If ThisValue = "ir" Then
Range("A" & x & ":AG" & x).Copy
Sheets("a").Select
NextRow = Range("A65536").End(xlUp).Row + 1
Range("A" & NextRow).Select
ActiveSheet.Paste
Sheets("a").Select

ElseIf ThisValue = "RR" Then

MsgBox "Hello"



End If
Next x
End Sub

What am I doing wrong. Pls help. Very fustrated
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Does this work?
Code:
Public Sub CopyRows()

    With Sheets("Sheet1")
        ' Find the last row of data
        FinalRow = .Range("A65536").End(xlUp).Row
        ' Loop through each row
        For x = 2 To FinalRow
            ' Decide if to copy based on column H
            ThisValue = .Range("H" & x).Value
            If ThisValue = "ir" Then
                NextRow = Sheets("a").Range("A65536").End(xlUp).Row + 1
                .Range("A" & x & ":AG" & x).Copy Sheets("a").Range("A" & NextRow)
        
            ElseIf ThisValue = "RR" Then
        
                MsgBox "Hello"
        
            End If
        Next x
    End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,148
Members
448,552
Latest member
WORKINGWITHNOLEADER

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