Delete rows with unused formulas

TycStyle

New Member
Joined
Mar 5, 2009
Messages
13
Hi all,

I have read many threads on deleting rows with certain (or no) values in cells. What I am trying to do is following:

I have a sheet containing formulas, when data is copied into the sheet (number of rows differs every time), I end up with good data for the pasted rows and the rest of rows which contain the default values and formulas (column A contains #VALUE!). What I want the script to do is only delete those remaining rows and end up with the needed data.
Because the #VALUE result is not regognized as a proper value, I haven't been able to solve this.....

Any help is appreciated.

Thanks in advance.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Welcome to the Board!

Try recording a macro using autofilter. Apply a filter and filter for #VALUE and then delete those rows.

Hope that helps.
 
Upvote 0
Hi both,

Thanks for the suggestion. I've tried that, but when I manually record the macro, it will use the values from the used data when selecting the rows.
F.e. in the first used data (for the recording) the first #VALUE! could be in row 220, but when new data is used it might be in row 200, which automatically gives a problem as the macro has recorded it should delete starting from row 220 and not 200.
 
Upvote 0
Ok,

What I have done now to create a solution:
This results in a Type Mismatsch Runtime Error 13......... Anyone?:confused::confused:


Sub Macro2()
'
'
'
Columns("A:A").Select
Selection.Copy
Columns("A:A").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.NumberFormat = "@"
Range("a:a").Select
For Each cell In Selection
If cell.Value = "#VALUE!" Then
Selection.EntireRow.Delete
End If
Next cell
Range("a1").Select
Selection.NumberFormat = "yyyymmdd"
End Sub
 
Upvote 0
You would need something like:

If iserror(cell.Value) Then

But then again that will delete all errors, even #N/A and #NUM just to name a few.

Can you post the code you recorded with the autofilter. It can probably be cleaned up to be more dynamic.

Hope that helps.
 
Upvote 0
This is the auto filter solution as tried earlier:

Sub DeleteErrorValues()
'

Rows("1:1").Select
Application.CutCopyMode = False
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:="#VALUE!"
Rows("221:221").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWindow.SmallScroll Down:=0
Selection.Delete Shift:=xlUp
Selection.AutoFilter
End Sub
 
Upvote 0
Try this:

Code:
Sub DeleteErrorValues()
'
 
Rows("1:1").AutoFilter
Rows("1:1").AutoFilter Field:=1, Criteria1:="#VALUE!"
Range("A2:A" & cells(rows.count,1).end(xlup).row).specialcells(xlCellTypeVisible).entirerow.Delete Shift:=xlUp
Rows("1:1").AutoFilter 
End Sub
Note that this is untested, so I would advise making a back up copy before trying it.

Hope that helps.
 
Upvote 0
All that did in the end is delete the headerrow in the process. No #VALUE! rows where deleted....
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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