Delete rows macro help

Jazzer

Board Regular
Joined
Jun 14, 2011
Messages
71
Hi Guys,

I am trying to use the following code to delete any row which contains #REF! from B13 to B50

HTML:
' SORT Macro
'
Dim LR As Long, i As Long
LR = Range("B" & Rows.Count).End(xlUp).Row
For i = LR To 13 Step -1
    If Range("B" & i).Value Like "*#REF!*" Then Rows(i).Delete
Next i
End Sub

However I am getting a run type error 13 - type mismatch

Any ideas where I am going wrong?

Many Thanks
James
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Try this:
Code:
Sub del()
Dim LR As Long, i As Long
LR = Range("B" & Rows.Count).End(xlUp).Row
For i = LR To 13 Step -1
    If Range("B" & i).Text = "#REF!" Then Rows(i).Delete
Next i
End Sub
 
Upvote 0
You might want to check the formula rather than the value.

Or you could use the iserror() function, but that won't distinguish between ref errors and other errors.
 
Upvote 0

Forum statistics

Threads
1,224,584
Messages
6,179,693
Members
452,938
Latest member
babeneker

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