Run Time error '1004':

Roller

Board Regular
Joined
Jan 31, 2005
Messages
113
I am getting an error message: "Delete method of range class filed" with my code below.
I have bolded the section that is highlighted when I try to debug this. I've picked up this code from another post, and it worked earlier, but now it does not. The only thing I've done was copy this macro to my personal.xls file. Thank you, in advance, for any assistance.

' This section will delete any rows where the amount field is blank.
Dim Rng As Range, Rng2 As Range
Set Rng = Range("j500").End(xlUp)
Do Until Rng.Row = 12
Set Rng2 = Rng.Offset(-1, 0)
If Rng = "" Then Rng.EntireRow.Delete
Set Rng = Rng2
Loop
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I have added one more line within two '================
i added a msgboxstatemnt for debug purposes only and changed into comments later.
at the last stage of running the macro the macro goes to J1 and it cannot find any offset (-1,0) and that is why the error.


now test it. (IN A COPIED FILE SO THAT THE ORGIINAL FILE IS NOT MESSED UP)
The modified macro is

Code:
Sub test()


Dim Rng As Range, Rng2 As Range
Set Rng = Range("j500").End(xlUp)
Do Until Rng.Row = 1
'==============
If Rng.Row = 1 Then Exit Sub
'===============================
Set Rng2 = Rng.Offset(-1, 0)
'msgbox rng.address
If Rng = "" Then Rng.EntireRow.Delete
Set Rng = Rng2
Loop
End Sub
 
Upvote 0
Thank you for your suggestion. It worked great! Its great to have a community like this to offer assistance. Thanks a million!
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,517
Members
448,968
Latest member
Ajax40

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