Macro Debug Error (Deleting a row)

spyldbrat

Board Regular
Joined
May 5, 2002
Messages
211
Office Version
  1. 365
Hello,

I want to delete all rows if column N reads "NULL". I was given the last two lines of this macro a while back from someone (I believe from this forum) and it has worked in the past. I applied this to my current macro but I am getting a debug error when I get to the last 2 lines. Can someone help me?

Dim UsdRws As Long
UsdRws = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Range("N2").Select
ActiveCell.FormulaR1C1 = _
"=IF(AND(RC[-6]=""Released"",RC[-2]=""PAID"",RC[-1]=""PAID""),""Null"",""Keep"")"
Range("n2:n" & UsdRws).FillDown
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("N:N").Replace What:="Null", Replacement:="#N/A", LookAt:=xlWhole, MatchCase:=False
Columns("N:N").SpecialCells(xlCellTypeConstants, xlErrors).EntireRow.Delete
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
What error message do you get & which line is highlighted when you click debug?
 
Upvote 0
Run-Time Error 1004: No Cells Were Found.

When I open the debug, the last line is highlighted. It is also not changing the "Null" to "#N/A" which is probably why I am getting this error, but I am not sure why it s not changing it to #N/A.
I don't really need to change Null to N/A, but in the past, I have not been able to get this to run on other macro's I added it to without using NULL and #N/A
 
Upvote 0
Do you have the actual word Null in col N?
 
Upvote 0
In an unused cell type
=Len(N4)
where N4 is a cell that contains "Null", what is the result?
 
Upvote 0
Try
Code:
   Dim UsdRws As Long
   UsdRws = Cells.find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
   With Range("N2:N" & UsdRws)
      .FormulaR1C1 = _
         "=IF(AND(RC[-6]=""Released"",RC[-2]=""PAID"",RC[-1]=""PAID""),""Null"",""Keep"")"
      .Value = .Value
      .Replace What:="Null", Replacement:="#N/A", LookAt:=xlWhole, MatchCase:=False
      .SpecialCells(xlCellTypeConstants, xlErrors).EntireRow.Delete
   End With
The problem is that you are only converting N2 to a value, so the rest of the column is still a formula.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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