Find #REF! errors in multiple tables and delete those rows

triangle3

New Member
Joined
Oct 14, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hello!

I'm working with a spreadsheet that has a summary tab - Sheets("Claim") - with 8 different tables on it. All the data on the tables has been pulled through from other tabs, each tab is for an individual project.
When a project is fully completed it's tab will be deleted from the workbook, which means that all the lines on the tables that came from it will be populated with #REF!
The tables are all within columns B through K

I'm hoping to put together a macro that can find all the rows that have #REF! errors and delete those rows.
The code I have currently is below, I'm stuck on the second half. Any assistance would be appreciated

Thank you

VBA Code:
Sub DeleteRefErrors()

'Clear filters for all tables
Dim lo As ListObject
  'Loop through all Tables on the sheet
  For Each lo In Sheets("Claim").ListObjects
    'Clear All Filters for entire Table
    lo.AutoFilter.ShowAllData
  Next lo

'Find and delete rows containing #REF!
Dim a As Long
For a = Range("B" & Rows.Count).End(xlUp).Row To 2 Step -1
   If Range("B" & a).Value = "#REF!" Then
       Rows(a).EntireRow.Delete
   End If
Next a

 
End Sub
 
Last edited by a moderator:

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Try this (for the last part)
VBA Code:
'Find and delete rows containing #REF!
Dim a As Long
For a = Range("B" & Rows.Count).End(xlUp).Row To 2 Step -1
If CStr(Range("B" & a).Value) = "Error 2023" Then ' This is the code for error "#REF!"
Rows(a).EntireRow.Delete
End If
Next a

Regards,
GB
 
Upvote 0
Solution
REF is an error, not a value. Maybe test for If IsError(Range("B" & a))

I don't think .Value = "Error 2023" will work as that would be literal text, but I could be wrong.
EDIT - I overlooked that the error in that code is supposed to be converted to a string, so yeah I guess that would be OK. But what if the error is not 2023?
Better to just test for any error? If you care what the error is then return the error with CVErr and act on particular error numbers with a Select Case block.
 
Last edited:
Upvote 0
Try this (for the last part)
VBA Code:
'Find and delete rows containing #REF!
Dim a As Long
For a = Range("B" & Rows.Count).End(xlUp).Row To 2 Step -1
If CStr(Range("B" & a).Value) = "Error 2023" Then ' This is the code for error "#REF!"
Rows(a).EntireRow.Delete
End If
Next a

Regards,
GB
This has worked perfectly! Thank you so much
 
Upvote 0
Another option:

VBA Code:
Sub detete_errors()
  Dim lo As ListObject
  
  For Each lo In Sheets("Claim").ListObjects
    With lo.DataBodyRange
      On Error Resume Next
      Intersect(.SpecialCells(xlCellTypeFormulas, xlErrors).EntireRow, .Columns).delete
    End With
  Next lo
End Sub
 
Upvote 0
@triangle3
Welcome to the MrExcel board!

For the future:
When posting vba code in the forum, please use the available code tags. It makes your code much easier to read/debug & copy. My signature block below has more details. I have added the tags for you this time. 😊
 
Upvote 0
@triangle3
Welcome to the MrExcel board!

For the future:
When posting vba code in the forum, please use the available code tags. It makes your code much easier to read/debug & copy. My signature block below has more details. I have added the tags for you this time. 😊
Apologies, I didn't realise! But I greatly appreciate you letting me know.
I will make a note for future, so I don't make the same mistake again

Thank you!
 
Upvote 0
Cheers. We understand that you are new here and it takes a while to know your way around. :)
 
Upvote 0

Forum statistics

Threads
1,224,241
Messages
6,177,370
Members
452,773
Latest member
D P

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