Macro to remove the #REF! generated after deleting rows?

jkharmer

Board Regular
Joined
Jul 7, 2008
Messages
77
Hi,

Does anyone know whether it is possible to create a smart macro which will remove all references to the #REF! which is left when rows are deleted. It would have to remove all trace of it from any equation it may be in (i.e. if it was in an averaging equation, it would need to remove the preceeding comma as well:

=average(a1,a2,!#REF!,a4 .........)

Thanks in advance, James
 
May have got it, that one! Will have to try a few more "what ifs ...", but could be sorted.

Thanks, James
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Sub AllRefErrors()
'Standard code module, like: Module1.
'Fix active sheet reference errors, by deleting the bad formula references.
Dim lngLstRow&, lngLstCol&
Dim rngMyRng As Range

On Error Resume Next

With ActiveSheet.UsedRange
lngLstCol = .Columns.Count + .Column - 1
lngLstRow = .Rows.Count + .Row - 1
End With

Set rngMyRng = ActiveSheet.Range(Cells(1, 1), Cells(lngLstRow, lngLstCol))

rngMyRng.SpecialCells(xlCellTypeFormulas, 16).Replace What:="#REF!,", Replacement:=""
rngMyRng.SpecialCells(xlCellTypeFormulas, 16).Replace What:="#REF!", Replacement:=""
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,884
Messages
6,127,563
Members
449,385
Latest member
KMGLarson

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